users@jersey.java.net

Re: [Jersey] Problem about file upload when using _at_FormDataParam

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 04 Dec 2009 10:26:12 +0100

On Dec 4, 2009, at 3:45 AM, michael_cheng wrote:

>
> Hi Paul,
> Thanks for your fast response.
> I read the jersey start and did not find some imformation about
> jersey-client-components configuration.Maybe I missed some details
> about
> that.

You do not need do to anything with that. I just wanted to know if you
got some logging output similar to that. For example on the server
side you might see:

INFO: Adding the following classes declared in META-INF/services/
jersey-server-components to the resource configuration:
   class com.sun.jersey.multipart.impl.FormDataMultiPartDispatchProvider
   class com.sun.jersey.multipart.impl.MultiPartConfigProvider
   class com.sun.jersey.multipart.impl.MultiPartReader
   class com.sun.jersey.multipart.impl.MultiPartWriter

If you have included the correct jars in the classpath for multipart
support as described in the dependencies document:

   https://jersey.dev.java.net/nonav/documentation/latest/user-guide.html
#d4e959

which states the maven dependency or the required jars: mimepull.jar
and jersey-multipart.jar.


If you are using the latest GlassFish v3 it ships with Jersey 1.1.4.1
and the multipart support and you should not have to include such a
dependency.

Paul.


> And which format should the file "jersey-client-components" be?XML
> or .mf?
> Or you can give me a example about that.
> Thanks in advance.
>
> Best Regards,
> Michael
>
> Paul Sandoz wrote:
>>
>> Hi,
>>
>> What version of Jersey are you using?
>>
>> Do you see output like:
>>
>> INFO: Adding the following classes declared in
>> META-INF/services/jersey-client-components to the client
>> configuration:
>> class com.sun.jersey.multipart.impl.MultiPartConfigProvider
>> class com.sun.jersey.multipart.impl.MultiPartReader
>> class com.sun.jersey.multipart.impl.MultiPartWriter
>>
>> in the logs?
>>
>> The behavior that you observe indicates that multipart MIME parsing
>> has not occurred and instead you are getting complete message (as you
>> indicate).
>>
>> Note that the name "file" in @FormDataParam("file") is incorrect,
>> you
>> need to use the same value as that in the name attribute on the form
>> input element, in this case "picture". However, i do not think that
>> will solve your problem.
>>
>> Paul.
>>
>> On Dec 3, 2009, at 3:49 PM, michael_cheng wrote:
>>
>>>
>>> Hi,
>>> It's about file upload when my project using jax-rs.I followed the
>>> code
>>> which the @FormDataParam API mentioned.
>>> Please help me about this issue.
>>>
>>> My client code:
>>> <form action="http://localhost:8080/testImage" method="post"
>>> enctype="multipart/form-data">
>>> <input type="file" name="picture" />
>>> <input type="submit" value="Send" />
>>> </form>
>>>
>>> My server code:
>>> @POST
>>> @Path("testImage")
>>> @Consumes(MediaType.MULTIPART_FORM_DATA)
>>> public void getImage(
>>> @FormDataParam("file") InputStream in) throws IOException{
>>> OutputStream os = new FileOutputStream(new
>>> File("D:\\good.jpg"));
>>> byte[] b = new byte[in.available()];
>>> int i = 0;
>>> while ((i = in.read(b)) >0) {
>>> os.write(b, 0, i);
>>> }
>>> os.flush();
>>> os.close();
>>> in.close();
>>> }
>>>
>>> When i upload a picture,the file "D:\\good.png" will show,and the
>>> fileSize
>>> is as the same .But I can not see the image when I open it.
>>> When debuging the program,I noticed that the InputStream contains
>>> both the
>>> file itself and the file description.Just
>>> like"----------789652236442--Content Type=jpg/
>>> image........xxxxxxxxxxxx(file
>>> itself)----78965222--".
>>> And my question is how can I just get the file itself in
>>> InputStream?
>>> Or I
>>> missed something?
>>> I will so appreciated if getting your help.Thanks.
>>> --
>>> View this message in context:
>>> http://n2.nabble.com/Problem-about-file-upload-when-using-FormDataParam-tp4106463p4106463.html
>>> Sent from the Jersey mailing list archive at Nabble.com.
>>>
>>> ---------------------------------------------------------------------
>>> 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/Problem-about-file-upload-when-using-FormDataParam-tp4106463p4110320.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>