Android - I want to show file upload progress to the user

前端 未结 7 606
一向
一向 2020-12-07 14:51

I upload photo to the server via the default HttpClient in Android SDK. I want to show progress in the user interface, is there a way to find out how much has been uploaded?

7条回答
  •  醉酒成梦
    2020-12-07 15:14

    For me HTTPClient didn't work. The bytes where buffered in parts and sent as total after the flush call. What worked was to sent it on socket level.

    You can use the HttpMultipartClient for this (updated link on 30-10-2011): http://code.google.com/p/rainbowlibs/source/browse/android/trunk/rainbowlibs/src/it/rainbowbreeze/libs/data/HttpMultipartClient.java?spec=svn94&r=94

    Specify the amount of bytes for each part and update the progressbar in the while loop:

    while (( line = reader.readLine()) != null && !headersEnd)

    Call the HttpMultipartClient as folow:

    HttpMultipartClient httpMultipartClient = new HttpMultipartClient("bluppr.com", "/api/order/create", 80);
    
    FileInputStream fis = new FileInputStream(path + fileName);
    httpMultipartClient.addFile(fileName, fis, fis.available());
    httpMultipartClient.setRequestMethod("POST");
    httpMultipartClient.send();
    

    At the server side use:

    
    

    I used this for Bluppr Postcards, worked like a charm. If you need more info let me know.

提交回复
热议问题