uupload with progressbar

A

autogoor

I am uploading files via POST to a web server, from the client.
Everything works great, the uploading, the reading of the file, works
100% perfect.


The problem is I can't figure out how to add a progress bar to a
single-file upload. I can't seem to figure out how many bytes have
actually been SENT over the internet connection.


I am using DataOutputStream and httpUrlConnection


Does anyone have any suggestions, ideas, or samples?


Thanks very much, I really appreciate it.
 
D

Daniel Tryba

In said:
I am uploading files via POST to a web server, from the client.
Everything works great, the uploading, the reading of the file, works
100% perfect.

The problem is I can't figure out how to add a progress bar to a
single-file upload. I can't seem to figure out how many bytes have
actually been SENT over the internet connection.

I am using DataOutputStream and httpUrlConnection

AFAIK you can't. httpUrlConnection has the nasty habit of buffering all
output and sending it in 1 batch (atleast that was the case in pre 1.5).
This can easlity be tested by sending *large* files.

You'll have to find an other http connection class that will give you
that option.
 
T

Thomas Weidenfeller

The problem is I can't figure out how to add a progress bar to a
single-file upload. I can't seem to figure out how many bytes have
actually been SENT over the internet connection.


I am using DataOutputStream and httpUrlConnection


Does anyone have any suggestions, ideas, or samples?

I haven't tried this, but:

use one of the set...StreamingMode() methods, so HttpURLConnection
doesn't buffer (you need to provide a chunk size or the total file
length, depending on the streaming mode you want to use). Then wrap the
file reading in a ProgressMonitorInputStream.

If you use the fixed' length mode, don't put any (large) buffers between
the InputStream and your code which copies the input stream to the
HttpURLConnection's output stream. Then the display should be reasonably
"accurate". Of course, you should put a BufferedReader around the
initial FileInputStream. Note, you do *not* want the order in the
example of the ProgressMonitorInputStream's API documentation.

Using chunked streaming mode might be the better alternative of the two
modes. If you do so, you could e.g. match chunk size and any internal
buffer size which might turn out to be useful.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top