uupload with progressbar

Discussion in 'Java' started by autogoor@yahoo.com, Mar 1, 2005.

  1. Guest

    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.
    , Mar 1, 2005
    #1
    1. Advertising

  2. Daniel Tryba Guest

    In comp.lang.java.help wrote:
    > 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.
    Daniel Tryba, Mar 1, 2005
    #2
    1. Advertising

  3. wrote:
    > 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

    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    Thomas Weidenfeller, Mar 1, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maka Sili
    Replies:
    0
    Views:
    492
    Maka Sili
    Aug 25, 2004
  2. Maka Sili
    Replies:
    0
    Views:
    385
    Maka Sili
    Aug 25, 2004
  3. Mehr H
    Replies:
    1
    Views:
    605
    Chris Jackson
    Nov 6, 2003
  4. Nilton Volpato
    Replies:
    0
    Views:
    369
    Nilton Volpato
    May 8, 2006
  5. Nilton Volpato
    Replies:
    0
    Views:
    419
    Nilton Volpato
    May 7, 2006
Loading...

Share This Page