users@jersey.java.net

Re: [Jersey] Re: Multipart Post

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 15 Mar 2010 09:20:10 +0100

Hi Steve,

This seems to be the opposite or at least a problem.

In Alexander's case it was a white space between the semi-colon and
the boundary parameter of the media type that cause an issue:

   This works:
   Content-Type: multipart/form-data;
boundary=----------------------------4e1144df2bb2

   While this does not:
   Content-Type: multipart/form-
data;boundary=----------------------------4e1144df2bb2


In your case it is *not* a white space between a semi-colon and a
parameter.

   Content-Disposition: form-data;name="file"

I think this is a bug in the RoR end point. Note that the spec of
Content-Disposition does not require a space character:

   http://www.ietf.org/rfc/rfc2183.txt

      disposition := "Content-Disposition" ":"
                     disposition-type
                     *(";" disposition-parm)

      disposition-type := "inline"
                        / "attachment"
                        / extension-token
                        ; values are not case-sensitive

      disposition-parm := filename-parm
                        / creation-date-parm
                        / modification-date-parm
                        / read-date-parm
                        / size-parm
                        / parameter


For WriterUtil see here:

   http://fisheye4.atlassian.com/browse/jersey/trunk/jersey/jersey-core/src/main/java/com/sun/jersey/core/impl/provider/header/WriterUtil.java?r=HEAD

The appendQuotedMediaType determines if a value needs to be quoted or
not.


I do not understand what you mean when you say:

   I'm wondering, how do I consume the MediaTypeProvider that I have
created in
   the above snippet?

Paul.

On Mar 12, 2010, at 9:41 PM, sshapero wrote:

>
> Hi Paul
>
>
> Paul Sandoz wrote:
>>
>>> Through a lot of brute force debugging, I've narrowed down the
>>> problem to a single line in the request.
>>>
>>> This works:
>>> Content-Type: multipart/form-data;
>>> boundary=----------------------------4e1144df2bb2
>>>
>>> While this does not:
>>> Content-Type: multipart/form-
>>> data;boundary=----------------------------4e1144df2bb2
>>>
>>
>
> I believe I am running into this same problem when trying to post a
> jpg to a
> Ruby on Rails "service end point". I'm coding a RESTful client using
> jersey, which produces this output:
>
> --Boundary_1_7290583_1268425967724
> Content-Type: text/plain
> Content-Disposition: form-data;name="filename"
>
> IMG_0168.jpg
> --Boundary_1_6270141_1268366891364
> Content-Type: image/jpg
> Content-Disposition: form-data;name="file"
>
> Notice the lack of whitespace between the semi-colon and the tokens
> around
> it.
>
> I copy and pasted your code as provided below. My current, non-
> working code
> looks like this:
>
> File file = new File("/Users/steve/Desktop/IMG_0168.jpg");
> FormDataMultiPart multiPart = new
> FormDataMultiPart().field("filename", file.getName())
> .field("file", file, MediaType.valueOf("image/jpg"));
>
> ClientResponse response =
> r.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class,
> multiPart);
>
> I'm wondering, how do I consume the MediaTypeProvider that I have
> created in
> the above snippet? Also, I noticed in the toString method this:
>
> WriterUtil.appendQuotedMediaType(b, e.getValue());
>
> What is WriterUtil? I just put b.append(e.getValue()) since I
> couldn't find
> anything out about WriterUtil.
>
> Thanks so much for any insight you can provide.
> -Steve
>
> --
> View this message in context: http://n2.nabble.com/Multipart-Post-tp4252846p4724316.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
>