0
이미지와 비디오를 청크로 웹 서버에 업로드하려합니다. 청크를 업로드 한 후에 다음 청크를 전송하기 위해 outputstream을 다시 호출해야합니다. 내가 가진 방법이 있습니다. 한 번만 outstream에 대한 호출합니다. 그때 그것은 왜 chunk를 업로드 한 후에 매번 outputstream을 호출하는 것이 필수적입니다. 내 코드 현재 코드가큰 파일을 android에서 웹 서버로 업로드하는 방법
header('Content-type:bitmap;charset=utf-8');
$super_parent_dir=$_POST["spd"];//super parent dic
$parent_dir=$_POST["pd"];//parent dic
$child_dir=$_POST["cd"];//super_child dic
$host_no=$_POST["queue_num"];//child_dic
$image_name=$_POST["image_name"];//file
$spd_path=$super_parent_dir;
$pd_path=$spd_path."/".$parent_dir;
$ch_path=$pd_path."/".$child_dir;
$f_folder=$ch_path."/".$host_no;
if(!is_dir($f_folder))
mkdir($f_folder, 0777);//echo $f_folder;
if(isset($_POST["Image_data"])){
$econded_string=$_POST["Image_data"];
$decode_string=base64_decode($econded_string);
$path=$f_folder.'/'.$image_name;
$file=fopen($path,'a');
$is_written=fwrite($file,$decode_string);
fclose($file);
if($is_written>0){
$connection=mysqli_connect("localhost","root","","imgae_db");
$query="insert into photos values('','$path','$image_name')";
$result= mysqli_query($connection,$query);
}}
공용 클래스 Media_uploader가 {
private String image_file;
public Media_uploader(File image){
this.image_file= String.valueOf(image);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
Bitmap bitmap= BitmapFactory.decodeFile(image_file);
ByteArrayOutputStream stream=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG,100,stream);
byte[] array=stream.toByteArray();
String a= Base64.encodeToString(array,Base64.DEFAULT);
try {
URL url=new URL("http://192.168.1.1**/db_mager/Medaia_Downloader.php");
HttpURLConnection httpURLConnection=(HttpURLConnection)url.openConnection();
httpURLConnection.setDoOutput(true);
OutputStream stream1=httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter=new BufferedWriter(new OutputStreamWriter(stream1,"UTF-8"));
String data= URLEncoder.encode("spd","UTF-8")+"="+URLEncoder.encode(Session_Data.getMyDatabase(),"UTF-8")+"&"+
URLEncoder.encode("pd","UTF-8")+"="+URLEncoder.encode(Session_Data.getMyCity(),"UTF-8")+"&"+
URLEncoder.encode("cd","UTF-8")+"="+URLEncoder.encode(Session_Data.getMyID(),"UTF-8")+"&"+
URLEncoder.encode("queue_num","UTF-8")+"="+URLEncoder.encode(String.valueOf(Session_Data.getActivity_Record()),"UTF-8")+"&"+
URLEncoder.encode("image_name","UTF-8")+"="+URLEncoder.encode(image_file,"UTF-8")+"&"+
URLEncoder.encode("Image_data","UTF-8")+"="+URLEncoder.encode(a,"UTF-8");
bufferedWriter.write(data);
bufferedWriter.flush();
bufferedWriter.close();
stream1.close();
InputStream inputStream=httpURLConnection.getInputStream();
inputStream.close();
} catch (java.io.IOException e) {
e.printStackTrace();
}
return null;
}
멀티 파트 데이터 업로드에 대해 들었습니까? –
예 멀티 파트로 더 좋은 옵션을 시도하십시오 – Saveen
지금까지 가지고있는 코드를 제공해주십시오. http://stackoverflow.com/help/how-to-ask 방문 – Olaia