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? Is it possible with HttpUrlConnection?
Show activity on this post. Open DevTools and on the Network page wait for the Uploading (25%)... message to pop up on the bottom left corner of Chrome. It doesn't work if you stop the upload half-way through by stopping the page, or going to another webpage, you have to let the upload finish.
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:
<?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded " .$_POST["order"]. " post"; } else{ echo "There was an error uploading the file, please try again!"; } ?>
I used this for Bluppr Postcards, worked like a charm. If you need more info let me know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With