users@jersey.java.net

Re: [Jersey] File upload with Jersey

From: Jeremy Espino <juest4_at_pitt.edu>
Date: Wed, 25 Feb 2009 09:36:19 -0800 (PST)

Is there a way to get the filename of the file that is uploaded in addition
to the InputStream?

P.S. One thing to note is that if you use the FormParam way don't include
jersey-multipart (only javax.mail) since it breaks it somehow

Thanks,
Jeremy



Paul Sandoz wrote:
>
>
> On Feb 24, 2009, at 2:53 PM, Robert Naczinski wrote:
>
>> Hi,
>>
>> thank you for your answer. I'm using Jakarta HttpClient.
>>
>> It must also be possible to use HTML Form or Jersey Client API.
>>
>
> OK so the client is sending multipart/form-data.
>
> You can do the following:
>
> @Consumes("multipart/form-data")
> @POST
> public void post(@FormParam("file") InputStream file) {
> ...
> }
>
> Alternatively you can use the MIME multipart API, see the following
> JavaDoc for more details:
>
>
> https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/contribs/jersey-multipart/index.html
>
> Specifically:
>
>
> https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/contribs/jersey-multipart/com/sun/jersey/multipart/FormDataMultiPart.html
>
>
> @Consumes("multipart/form-data")
> @POST
> public void post(FormDataMultiPart formData) {
> FormDataPart p = formData.getField("file");
> InputStream file = p.getValueAs(InputStream.class);
> ...
> }
>
> For either of the above you require a dependency on JavaMail:
>
>
> https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/jersey/dependencies.html
>
> You can reuse the MIME multipart API on the Jersey client side.
>
> Paul.
>
>> Robert
>>
>> 2009/2/24 Paul Sandoz <Paul.Sandoz_at_sun.com>:
>>>
>>> On Feb 24, 2009, at 2:08 PM, Robert Naczinski wrote:
>>>
>>>> Hi,
>>>>
>>>> it is possible with Jersey to receive a file from a request? If is
>>>> so,
>>>> has anybody a snippet?
>>>>
>>>
>>> Do you mean the uploading of a file from say a browser using an
>>> HTML form?
>>>
>>> Or do you mean a client directly sending the bytes of the file as a
>>> request
>>> entity and the server should reproduce a file that contains those
>>> same bytes
>>> on the server-side?
>>>
>>> Paul.
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>

-- 
View this message in context: http://n2.nabble.com/File-upload-with-Jersey-tp2377844p2385042.html
Sent from the Jersey mailing list archive at Nabble.com.