Re: Multipart file upload in applet

Discussion in 'Java' started by Arne Vajhøj, Jul 18, 2008.

  1. Kenneth P. Turvey wrote:
    > I'm having some difficulty getting file upload to work. I'm using some
    > sample code of questionable utility and I was hoping someone here could
    > give me a hand.
    >
    > The basic problem is that I need to post to a servlet an image and some
    > associated metadata. It should look just like it does when it is posted
    > by the following web page:
    >
    > <html>
    > <head>
    > <title>Image Uploader</title>
    > </head>
    > <body>
    > <form method="POST" enctype="multipart/form-data"
    > action="http://www.squeakydolphin.com/ImageUpload/ImageUpload">
    > Category<input type="text" name="Category" /><br/>
    > UserId<input type="text" name="UserId" /><br/>
    > Image<input type="file" name="Image" /><br/>
    > <input type="submit" />
    > </form>
    > </body>
    > </html>
    >
    >
    > It is accepted as multipart data on the server end and that works fine.
    > I just can't seem to get the client to produce the write output. Is
    > there a class library I can use to ease getting this correct?


    Use the Apache HttpClient package, classes HttpClient, PostMethod
    and MultipartRequestEntity !

    Arne
     
    Arne Vajhøj, Jul 18, 2008
    #1
    1. Advertising

  2. In article <487fd6c5$0$90263$>,
    Arne Vajhøj <> wrote:

    > Kenneth P. Turvey wrote:
    > > I'm having some difficulty getting file upload to work. I'm using some
    > > sample code of questionable utility and I was hoping someone here could
    > > give me a hand.
    > >
    > > The basic problem is that I need to post to a servlet an image and some
    > > associated metadata. It should look just like it does when it is posted
    > > by the following web page:
    > >
    > > <html>
    > > <head>
    > > <title>Image Uploader</title>
    > > </head>
    > > <body>
    > > <form method="POST" enctype="multipart/form-data"
    > > action="http://www.squeakydolphin.com/ImageUpload/ImageUpload">
    > > Category<input type="text" name="Category" /><br/>
    > > UserId<input type="text" name="UserId" /><br/>
    > > Image<input type="file" name="Image" /><br/>
    > > <input type="submit" />
    > > </form>
    > > </body>
    > > </html>
    > >
    > >
    > > It is accepted as multipart data on the server end and that works fine.
    > > I just can't seem to get the client to produce the write output. Is
    > > there a class library I can use to ease getting this correct?

    >
    > Use the Apache HttpClient package, classes HttpClient, PostMethod
    > and MultipartRequestEntity !
    >
    > Arne


    Or build the POST manually and use Sun's Http code. It's not that hard
    to stick a file inside a template.

    Using Apache libraries in an Applet could really drive up bandwidth
    costs for some uses.

    --
    Goolge is a pro-spamming service. I will not see your reply if you use Google.
     
    Kevin McMurtrie, Jul 18, 2008
    #2
    1. Advertising

  3. Lew wrote:
    > Arne Vajhøj wrote:
    >>> Use the Apache HttpClient package, classes HttpClient, PostMethod and
    >>> MultipartRequestEntity !

    >
    > Also,
    > <http://commons.apache.org/fileupload/>


    That is server side. I am pretty sure that the question
    was for client side.

    Arne
     
    Arne Vajhøj, Jul 18, 2008
    #3
  4. Kevin McMurtrie wrote:
    > In article <487fd6c5$0$90263$>,
    > Arne Vajhøj <> wrote:
    >
    >> Kenneth P. Turvey wrote:
    >>> I'm having some difficulty getting file upload to work. I'm using some
    >>> sample code of questionable utility and I was hoping someone here could
    >>> give me a hand.
    >>>
    >>> The basic problem is that I need to post to a servlet an image and some
    >>> associated metadata. It should look just like it does when it is posted
    >>> by the following web page:
    >>>
    >>> <html>
    >>> <head>
    >>> <title>Image Uploader</title>
    >>> </head>
    >>> <body>
    >>> <form method="POST" enctype="multipart/form-data"
    >>> action="http://www.squeakydolphin.com/ImageUpload/ImageUpload">
    >>> Category<input type="text" name="Category" /><br/>
    >>> UserId<input type="text" name="UserId" /><br/>
    >>> Image<input type="file" name="Image" /><br/>
    >>> <input type="submit" />
    >>> </form>
    >>> </body>
    >>> </html>
    >>>
    >>>
    >>> It is accepted as multipart data on the server end and that works fine.
    >>> I just can't seem to get the client to produce the write output. Is
    >>> there a class library I can use to ease getting this correct?

    >> Use the Apache HttpClient package, classes HttpClient, PostMethod
    >> and MultipartRequestEntity !

    >
    > Or build the POST manually and use Sun's Http code. It's not that hard
    > to stick a file inside a template.
    >
    > Using Apache libraries in an Applet could really drive up bandwidth
    > costs for some uses.


    My old version of HttpClient is only 225 KB. That is not much today.

    And it can actually be a bit tricky to implement POST multipart
    100% correct. It is easy to write something that works with some
    forgiving server, but to get it to work with a strict server
    requires either some standards reading or some sniffing.

    Arne
     
    Arne Vajhøj, Jul 18, 2008
    #4
    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. Matt
    Replies:
    8
    Views:
    142,524
    zeeshanakhter2009
    May 26, 2012
  2. Replies:
    3
    Views:
    8,737
    Ross Bamford
    Nov 5, 2005
  3. Matt
    Replies:
    1
    Views:
    11,191
    David Dorward
    Oct 12, 2004
  4. leoboiko
    Replies:
    0
    Views:
    384
    leoboiko
    Aug 6, 2008
  5. Replies:
    1
    Views:
    410
Loading...

Share This Page