users@jersey.java.net

Re: Specifying Multipart file upload content type

From: ManiKanta G <go4mani_at_gmail.com>
Date: Sun, 21 Nov 2010 10:29:28 +0530

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
>