users@jersey.java.net

Re: [Jersey] Re: Multipart Post

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 16 Mar 2010 18:42:00 +0100

Hi Steve,

See the class FormDataContentDisposition class and the builder of that:

https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/core/header/FormDataContentDisposition.FormDataContentDispositionBuilder.html

you can add instances of FormDataBodyPart to the multipart:

https://jersey.dev.java.net/nonav/apidocs/latest/contribs/jersey-multipart/com/sun/jersey/multipart/FormDataBodyPart.html
#FormDataBodyPart
%28com.sun.jersey.core.header.FormDataContentDisposition,
%20java.lang.Object,%20javax.ws.rs.core.MediaType%29

Also take a look at FileDataBodyPart:

https://jersey.dev.java.net/nonav/apidocs/latest/contribs/jersey-multipart/com/sun/jersey/multipart/file/FileDataBodyPart.html

which might better suite your needs, which will also set the
modification date and size

Paul.

On Mar 16, 2010, at 6:15 PM, sshapero wrote:

>
> Hi Paul
>
> There is an issue logged against RoR already for the issue, but
> because RoR
> requires you to hardcode dependencies into your actual code, we
> weren't able
> to use the work around (you have to search and replace for version
> numbers
> in the Rails source code, which then requires changing your deployment
> process to use your hand-rolled Rails stack). This whole experience
> has me
> very thankful for Maven.
>
> So I've now got my Content-Disposition with the space after the semi-
> colon,
> resolving part 1 of my problem. Here's my next question. I'd like
> the
> Content-Disposition header to look like this:
>
> Content-Disposition: form-data; name="image"; filename="foo.jpg"
> Content-Type: image/jpeg
>
> What kind of MultiPart allows me to have the 2 key-value pairs as a
> part of
> one header? Right now I do this:
>
> MyMultiPart multiPart = new MyMultiPart().field("filename",
> file.getName())
> .field("image", file, MediaType.valueOf("image/jpg"));
>
> (Recall MyMultiPart inherits from FormDataMultiPart). I get this
> output:
>
> --Boundary_1_5579641_1268720872443
> Content-Type: text/plain
> Content-Disposition: form-data; name="filename"
>
> foo.jpg
> --Boundary_1_5579641_1268720872443
> Content-Type: image/jpg
> Content-Disposition: form-data; name="image"
>
> TIA
> Steve
> --
> View this message in context: http://n2.nabble.com/Multipart-Post-tp4252846p4745023.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
>