Show progress while uploading image to server using MultipartEntity

I am posting an image to the server using this code:

public void loadImage(final File image) {
    new Thread(new Runnable() {
        public void run() {
                MultipartEntity entity=new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
                entity.addPart("image", new FileBody(image));
                HttpResponse response=sendMultipart("", entity);
            }catch(Exception e){

public HttpResponse sendMultipart(final String URL,MultipartEntity entity) throws IOException{
    HttpPost httpPost=new HttpPost(URL);
    return sendRequest(httpPost);

public HttpResponse sendRequest(final HttpRequestBase mhttp) throws IOException{
    HttpParams params=new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, REST.CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, REST.SERVER_TIMEOUT);
    HttpClient httpClient=new DefaultHttpClient(params);
    HttpResponse response=httpClient.execute(mhttp);

    //if we're been redirected then try to get relocated page
        Header [] headers=response.getHeaders("Location");
        if(headers!=null && headers.length!=0){
            String newUrl=headers[headers.length-1].getValue();
            HttpGet httpGet=new HttpGet(newUrl);

    return response;


The question is: how do I make the download progress?

Please note that this question is NOT "how to show progress", "how to upload an image". I figured it was better to use AsyncTask, but I still don't know how to make progress.


source to share

All Articles