【发布时间】:2016-07-17 10:49:31
【问题描述】:
我正在使用此代码将文件从我的 android 上传到服务器,但我不知道我的文件上传了多少(例如 30MB 来自 100MB)!
有什么办法吗?
String url = "http://yourserver";
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),
"yourfile");
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true); // Send in multiple parts if needed
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
//Do something with response...
} catch (Exception e) {
// show error
}
【问题讨论】:
标签: android file-upload httpclient progressdialog progress