users@jersey.java.net

Re: [Jersey] Sending a MultiPart JAXB object

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 24 Feb 2009 16:52:55 +0100

HI Amir,

Yes, using MIME multipart is a good approach.

Specifically for multipart/form-data see:

  https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/contribs/jersey-multipart/com/sun/jersey/multipart/FormDataMultiPart.html

which is what you should be using so you can name the parts and thus
they can be identified correctly by the server-side.

If you can name the audio in the MIME body part then strictly speaking
you do not need to name it in the XML meta data you are sending. But
it depends on your design really.

I think you should be careful using the file name the client has given
to be used directly for file operations on the server as a nasty
client could create a file name that causes problems e.g. overwriting
files and could thus be a security risk.

Paul.


On Feb 24, 2009, at 4:38 PM, Amir Pourteymour wrote:

> Hi,
> I am planning to send an audio file (audioFile) in addition to my
> JAXB object (myJAXBObject). So the questions are:
>
> Is it a good way to send an audio file?
> Is it good to send the name of audio as an element of myJAXBObject
> (myJAXBObject.getAudioFileName()) to store it with the same name on
> the storage of the server?
> MultiPart myPart = new MultiPart().bodyPart(
> new BodyPart(myJAXBObject,
> MediaType.APPLICATION_XML_TYPE)).bodyPart(
> new BodyPart(audioFile,
> MediaType.APPLICATION_OCTET_STREAM_TYPE));
>
> Client client = Client.create();
> WebResource resource = client.resource(myURI);
> Builder builder = resource.accept(MediaType.MULTIPART_FORM_DATA);
> builder.entity(myPart , MediaType.MULTIPART_FORM_DATA);
> ClientResponse acknowledgment = builder.post(ClientResponse.class,
> myPart );
>
> thanks,
>
> --
> Amir