users@jersey.java.net

Re: Specifying Multipart file upload content type

From: Kevin Duffey <andjarnic_at_yahoo.com>
Date: Sun, 21 Nov 2010 17:06:39 -0800 (PST)

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? 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)?


--- On Sat, 11/20/10, ManiKanta G <go4mani_at_gmail.com> wrote:

From: ManiKanta G <go4mani_at_gmail.com>
Subject: Re: Specifying Multipart file upload content type
To: "Jersey users list" <users_at_jersey.java.net>
Date: Saturday, November 20, 2010, 8:59 PM


Hi,

Does any one knows how to do it? Any help is appreciated. 

ManiKanta G
twitter.com/ManiKantaG



On Wed, Nov 17, 2010 at 1:07 PM, ManiKanta G <go4mani_at_gmail.com> wrote:



Hi,

For uploading file, I've the following code (Jersey 1.4, Mimepull 1.4, jersey-multipart1.4)
        @POST
        @Path("upload") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})


        public Response uploadFile(@FormDataParam("uploadFile") FormDataContentDisposition disposition ,  @FormDataParam("uploadFile") UploadObject stream) {


                ..... }

If the file has the xml content, the JAXB is doing unmarshaling the upload file content into UploadObject without any error. 



But, if I upload a file that contains some JSON formatted data, I m getting 'org.xml.sax.SAXParseException: Content is not allowed in prolog' error, as the content type of the file is set to text/plain by the browser.



        ------WebKitFormBoundarywsLgmqEHXTyMGEo2 Content-Disposition: form-data; name="uploadFile"; filename="TestFile.txt"


        Content-Type: text/plain
        ------WebKitFormBoundarywsLgmqEHXTyMGEo2--



So, is there any way to set the Content-Type of the multipart upload file to application/json from the client side or some code that identifies the type of the content based on the content (as bad as, may be like trail and hit method) at server side.



Thanks,
ManiKanta G
twitter.com/ManiKantaG