0
我想上传图片和视频到网络服务器的块 但上传一个块后,我不得不再次调用outputstream传输下一个块。是否有任何方式,我有呼吁outstream仅once.If没有,那么为什么它是neccassary上传块之后调用的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扩展的AsyncTask {
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