users@jersey.java.net

Sending a MultiPart JAXB object

From: Amir Pourteymour <pourteymour_at_gmail.com>
Date: Tue, 24 Feb 2009 10:38:07 -0500

Hi,
I am planning to send an audio file (audioFile) in addition to my JAXB
object (myJAXBObject). So the questions are:


   1. Is it a good way to send an audio file?
   2. 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