users@jersey.java.net

[Jersey] Documentation / Tutorial on using jersey-multipart

From: sarat.pediredla <sarat.pediredla_at_gmail.com>
Date: Sun, 14 Dec 2008 08:15:50 -0800 (PST)

Hi,

I have been trawling the mailing list for the past hour trying to find a
solution to this and could not, so I gave up and thought I might just ask.

I have a REST API, which work's great when serialising from and to JSON/XML.
This serves me great but now I want to start accepting attachments
(primarily binary images) through the REST API and wanted to see how this
could be achieved.

Here is a sample requirement,

"I want to be able to POST a note, along with an attachment to the API and
have it create the Note (which is a JAXB Bean) and save the attachment to
file, assigning the disk file path to Note.setAttachmentPath(String
filePath))"

The problem is being able to POST both the Note object and binary attachment
in 1 request, so I figured the only easy way for me to get this to work is
use @Consumes("multipart/form-data").

I hear I could use jersey-multipart to handle this, but I can find no
documentation on how this will work. Ideally, I would like something like
this,

         @POST
         @Consumes("multipart/form-data")
         public String postNote(
                 Note note,
                 File file)
throws Exception {
             ..
         }

I saw another note from Paul Sandoz somewhere which mentions the use of
FormDataContentDisposition like below,

         @POST
         @Consumes("multipart/form-data")
         public String post(
                 @FormParam("file") JAXBBean f,
                 @FormParam("file") FormDataContentDisposition fdc)
throws Exception {
             ..
         }

However, this doesn't really explain how to use the jersey-multipart request
to read the file and save it (I would prefer to use Apache Commons to save
the file to disk, like I do in my struts2 actions)

Any help?
-- 
View this message in context: http://n2.nabble.com/Documentation---Tutorial-on-using-jersey-multipart-tp1654871p1654871.html
Sent from the Jersey mailing list archive at Nabble.com.