Skip to content

Uploading progress #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
voidberg opened this issue Oct 21, 2012 · 42 comments
Closed

Uploading progress #118

voidberg opened this issue Oct 21, 2012 · 42 comments
Assignees
Labels
Milestone

Comments

@voidberg
Copy link

Hey,

When uploading files to the server, is there a way I can have a callback to see the progress of the upload?

Thanks

@jendib
Copy link

jendib commented Nov 16, 2012

This library uses standard HttpClient, so I don't know if it's possible, but if it is, I would be very interested too.

@voidberg
Copy link
Author

I managed to do it but it was a bit tricky. I'll update this post in a bit with an example.

@voidberg
Copy link
Author

I've detailed the way to do this when uploading files (it could be adapted to other post calls as well) here (bottom, read uploading large files and progress callback): https://github.com/voidberg/Android-Drupal-Sdk/blob/master/README.md

You can grab the CustomMultiPart.java file here: http://android.svn.wordpress.org/trunk/src/org/xmlrpc/android/CustomMultipartEntity.java

@fahadishaque35
Copy link

Hi @voidberg ... the link is broken. Can you please update it.
Thanks

@voidberg
Copy link
Author

I updated the name of the repository, sorry. Here's a correct link: https://github.com/voidberg/DrupalDroid/blob/master/README.md

@nadam
Copy link

nadam commented Apr 12, 2013

I think this issue should be opened again. It would be a great feature to give users the possibility without a bunch of boiler plate code. I'm willing to implement it and send a pull request if it's likely to be accepted.

@loopj
Copy link
Collaborator

loopj commented Apr 12, 2013

One of my main concerns is that this feature will increase the size/complexity of the library. If you think this can be implemented in a simple way, I'm open to discussion.

@nadam
Copy link

nadam commented Apr 14, 2013

I think it can be very simple. I'll give it a try and let you know the result.

@gaoyong06
Copy link

I am beset by the question ,Now.

@fahadishaque35
Copy link

@nadam ma man!!!!!
@loopj almost perfect lib but my clients wanted a progress bar, this was the only reason i couldn't use this. I have some commercial apps in-line, hopefully would use this lib again. Cheers great work.

@nadam
Copy link

nadam commented Apr 17, 2013

I've analyzed the code now. Not as simple as I thought, but I think I can solve it and make it pretty simple.

@loopj as you probably know there are issues with the whole files being read into memory in SimpleMultipartEntity causing OutOfMemory. I think I can solve that at the same time with pretty small changes.

However, the number of open issues, pull requests and printStackTrace() statements makes me a bit worried. Not sure if I should spend time cleaning up this project or find some fork of it or other alternative. I'm open to suggestions and recommendations. Thanks.

@nadam
Copy link

nadam commented Apr 19, 2013

Would it be reasonable to deprecate the methods that add files as input streams in favor of similar methods using File objects?

@fahadishaque35
Copy link

How about using FileBody instead of InputStream?

@nadam
Copy link

nadam commented Apr 19, 2013

FileBody is part of httpmime that we don't want to include because of the size, but I'm implementing something similar. I mean when adding a File object it will be read as a stream later when it's sent on the socket.

@fahadishaque35
Copy link

hi @nadam . Hope your still working on this. Eagerly waiting for a merge.
Cheers

@nadam
Copy link

nadam commented Apr 22, 2013

I realized that I can't deprecate the stream methods. One example is if you read an image from disc and scaling it down etc. Now you have a new image in memory that you want to send to the server. No file or file object.

But a stream can only be read once, so it has to be read into memory. Otherwise the retry functionality won't work. Some streams can be reset() but it's not obvious when/where to close() the streams.

So I will focus on implementing it for files and leave the stream implementation in it's current state. The first part, solving the memory problem, is almost ready for testing. Hopefully, the upload progress is pretty easy after that.

@jensh
Copy link

jensh commented May 10, 2013

This small patch works fine for me:
jensh@256ec9425b4

To get notifications every 64kbytes override onProgress of AsyncHttpResponseHandler:

RequestParams params = new RequestParams();
params.put("image", imageStream, "image.jpg", "image/jpeg");
client.post(url, params, new AsyncHttpResponseHandler() {
            @Override
            public void onProgress(int position, int length) {
                Log.d("progress", "pos: " + position + " len: " + length);
            }
})

What do you think? Comments welcome!

@nadam
Copy link

nadam commented May 11, 2013

Thanks @jensh. That's similar to what I had planned. I finally pushed my changes and merged yours over at https://github.com/nadam/android-async-http, so now it contains both upload progress and minimal memory allocation. I haven't had time to test it though. I hope someone else wants to do that.

@ebuildy
Copy link
Contributor

ebuildy commented Jun 24, 2013

Hi @nadam , thanks for your contribution of course Progress callback is a great feature, is your changes are in the loopj JAR already ?

@nadam
Copy link

nadam commented Jun 24, 2013

It's not merged into loopj's repo yet. I never got the time to test it so I never sent a pull request or anything. Would be awesome if you could test it for us. I can send you my jar-file or you can build it yourself from https://github.com/nadam/android-async-http. Thanks.

@ebuildy
Copy link
Contributor

ebuildy commented Jun 24, 2013

Yes I just add it on my project, 5 min to import and use it. Work nicely, I can see my progress bar filling well, thanks you ! (I am using Php as backend, with Nginx as HTTP server. Tested on my Wiko under Android 4.0).

@nadam
Copy link

nadam commented Jun 24, 2013

Cool! Thanks @ebuildy! Now I just have to figure out how to make a pull request properly. I forgot to create a topic branch for my changes and I've also included one unrelated bug fix. Not sure if it's good enough to just create a pull request anyway or if I need to do something first. I don't know what it takes to get a pull request accepted by @loopj and my time is quite limited too at the moment.

@wemakeweb
Copy link

+1

@amincheloh
Copy link

+1 waiting for merge

@twig
Copy link

twig commented Jul 17, 2013

+1 hoping to see this merged, it's the last thing I need from this library!

@chug2k
Copy link

chug2k commented Jul 21, 2013

+1

@stephenzl
Copy link

+1

1 similar comment
@pbelokopytov
Copy link

+1

@nadam
Copy link

nadam commented Aug 28, 2013

No manual/docs yet but it's pretty straight forward, just override onProgress() in AsyncHttpResponseHandler. The code is over at https://github.com/nadam/android-async-http.
A pull request is waiting to be approved at #269.

@twig
Copy link

twig commented Aug 29, 2013

Is that branch up to date with the main repository?

@jeshurun
Copy link

jeshurun commented Sep 6, 2013

+1 works perfectly.

@chug2k
Copy link

chug2k commented Sep 22, 2013

hmm I also see #302 by @jensh

@jensh
Copy link

jensh commented Sep 23, 2013

#302 is included in #269. Additional @nadam improved the file and stream handling. I opened #302 because @loopj asked for smaller pull requests.

@smarek
Copy link
Member

smarek commented Oct 14, 2013

So this is now provided by linked commit.

iNdieboyjeff pushed a commit to iNdieboyjeff/android-async-http that referenced this issue Oct 15, 2013
# By mareksebera (7) and Ankush Sachdeva (1)
# Via Ankush Sachdeva (1) and Marek Sebera (1)
* 'master' of https://github.com/loopj/android-async-http:
  Added Proxy Authentication ; fixes android-async-http#328
  Fixed wrong static field, Closing android-async-http#229
  Manual merge, Closing android-async-http#269, android-async-http#118, Closing android-async-http#10, Closing android-async-http#127, android-async-http#154
  Closes android-async-http#137
  Removing duplicate call
  Closing android-async-http#179
  Updated Gradle Android tools version
  Cleaning up error message output
@hillold
Copy link

hillold commented Nov 1, 2013

Hi @nadam I am using the onProgress() of BinaryHttpResponseHandler class to get the upload progress. The total content size was 315197 bytes and the progress jumps from 0% to 98% (315161 bytes copied) all of a sudden. How can I achieve the smoothness of the progress report? Can I control how many bytes will be written each time so that the progress looks smoothly incremental throughout the process?

@nadam
Copy link

nadam commented Nov 1, 2013

@hilloldebnath Normally 4096 bytes are written each time except the first and last parts that are smaller. However, this is only if you add File objects. If you use streams you will currently see the progress jump like you describe.

@hillold
Copy link

hillold commented Nov 1, 2013

@nadam , thanks for the clarification. I have couple of byte[] contents. So, I have added them as ByteArrayInputStream() to the RequestParams object. What would be your suggestion if I want to achieve a smooth upload progress in this situation?

@nadam
Copy link

nadam commented Nov 3, 2013

@hilloldebnath you would need to change SimpleMultipartEntity.writeTo() where out.writeTo(outstream) is called. Another option would be to write the data to files first and then use File objects.

I think this can be considered a bug so feel free to write a separate issue for it and I (or someone else) can have a look at it.

@hmedat
Copy link

hmedat commented Mar 27, 2014

@nadam

At first Thank you for awesome library,Secondly I have a problem,
I uploaded a file to server 'PHP' using this code:

AsyncHttpClient client = new AsyncHttpClient();
AsyncHttpResponseHandler httpResponseHandler = createHTTPResponseHandler();
File file =new File(filePath);
RequestParams params = new RequestParams();
params.put("data", file);
client.post(context, url, params, httpResponseHandler);
This is work fine WITH PROGRESS,

But when I used this code to upload a file to server '.NET'
NOT WORK, I solved it by put a file in HttpEntity like this

HttpEntity entity = new FileEntity(file, "multipart/form-data");
client.post(context, url, entity, "multipart/form-data", httpResponseHandler);

It's worked file WITH NO PROGRESS JUST ONE FLUSH,.

I need to show progress when starting upload.
Thanks

@nadam
Copy link

nadam commented Mar 28, 2014

@hmedat2008 I can't see how the server side platform could affect the behavior. Sounds like a bug in .NET or in the code running in .NET. I don't know enough about .NET to help you with that. Sorry.

@sizrar
Copy link

sizrar commented Oct 21, 2015

@hmedat2008 @nadam Highly possible that the server doesn't give a proper "Content-length" value in the headers ? I had the same issue with a varnish in front of an apache that was removing some headers by misconfiguration...

@smarek
Copy link
Member

smarek commented Oct 26, 2015

@sizrar if you have issue please open new ticket, this one is back from 2014
Closing for obsoleteness

@android-async-http android-async-http locked and limited conversation to collaborators Oct 26, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests