我将文件(视频和照片)从 android 上传到 php 服务器,并使用以下代码:
@SuppressWarnings("deprecation")
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
Utils.d(Config.REST_SERVER + url_connect);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(Config.REST_SERVER+url_connect);
try {
@SuppressWarnings("deprecation")
MultipartEntity entity = new MultipartEntity();
entity.addPart("userId", new StringBody(this.userId));
entity.addPart("orderId", new StringBody(this.orderId));
Utils.d("size totale avant : "+this.files.size());
int i = 0;
for(File f:this.files){
entity.addPart("nameFile", new StringBody(f.getName()));
i++;
entity.addPart("files[]", (ContentBody) new FileBody(f));
}
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity httpEntity = response.getEntity();
is = httpEntity.getContent();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
Log.d("Create Response", json);
jObj = new JSONObject(json);
Log.d("Create Response", jObj.toString());
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
return null;
}
我想制作与文件一样多的进度条,这些进度条将根据发送到服务器的字节百分比改变状态
有没有办法做到这一点
先感谢您