users@jersey.java.net

Re: Specifying Multipart file upload content type

From: ManiKanta G <go4mani_at_gmail.com>
Date: Mon, 22 Nov 2010 22:49:52 +0530

>
> Maybe a little out of context of your original question, but isn't what
> you're trying to do allow any type of file uploaded? I thought the
> multi-part stuff was for any file, not where you upload an xml file and it
> is parsed as it's uploaded?


First, thanks Keven and Paul.

Though it is not specified by the spec exactly, in general browsers are
setting the correct MIME only (I've tested this by upload images, other file
and inspected the req-resp cycle). If the browser can't guess the MIME type
of the file, it'll set the default one, text/plain.

So I though, while unmarshalling there might be some sort of mechanism in
where I can specify/configure the expected MIME.


> I would think if you were trying to do that, you'd upload the file as a
> file and save it, then process the file once it's saved on the server side
> (or in a stream of some sort)?


Sort of... Requirement is the bean will be marshalled into a file and would
be unmarshalled into bean from the upload (previous marshalled) data. First,
I've marshalled the data into JSON format, but while unmarshalling JAXB is
not able to identify the correct Content-Type (as the browser send the
multipart content-type as text/plain) and resorting to its natural behavior,
the XML, and reporting prolog error.

Now that I've changed the marshalling to XML, unmarshalling is pretty
straight forward.


http://jersey.java.net/nonav/apidocs/latest/contribs/jersey-multipart/com/sun/jersey/multipart/FormDataParam.html
>
> @FormDataParam("uploadFile") FormDataBodyPart p
>
> If you want to reduce the number of parameters for the part you can just do
> the above and obtain the content disposition and entity from "p".
>
>
Look like this will do the magic for me! Thanks Paul, again.


ManiKanta G
twitter.com/ManiKantaG