我正在开发一个需要使用 Multipart 上传图片的项目。这是我的代码:
public void doUploadGIF(File image) {
try {
long start = System.currentTimeMillis();
HttpPost httppost = new HttpPost(
"myurl");
MultipartEntity multipartEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("gif", new FileBody(image));
httppost.setEntity(multipartEntity);
mHttpClient.execute(httppost, new PhotoUploadResponseHandler());
long end = System.currentTimeMillis();
System.out.println("Time for uploading:"
+ String.valueOf(end - start));
} catch (Exception e) {
Log.e("Upload", "Error while uploading");
}
}
private class PhotoUploadResponseHandler implements ResponseHandler<Object> {
@Override
public Object handleResponse(HttpResponse response)
throws ClientProtocolException, IOException {
HttpEntity r_entity = response.getEntity();
String responseString = EntityUtils.toString(r_entity);
Log.d("UPLOAD", responseString);
return null;
}
}
现在在客户端(Android)我让用户知道上传的过程(百分比)。我怎样才能做到这一点?感谢您的关注 !