users@jersey.java.net

Re: [Jersey] form multipart post "Missing start boundary" exception

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 12 Aug 2009 21:40:00 +0200

Hi Jonathan,

Your HTML looks fine, so i am not sure why it is failing. Perhaps you
can enable server side logging and see if the HTTP request has a
Content-Type header with a boundary parameter:

https://jersey.dev.java.net/nonav/apidocs/1.0.3/jersey/com/sun/jersey/api/container/filter/LoggingFilter.html


Note that the use of multpart/form-data with @FormParam has been
deprecated due to semantic issues overloading for two different media
types that operate on characters and bytes. I need to log a warning
stating that it is deprecated.

I recommend using the jersey-multipart module and use @FormDataParam:

   https://jersey.dev.java.net/nonav/apidocs/1.0.3/contribs/jersey-multipart/com/sun/jersey/multipart/FormDataParam.html

For example:

     @POST
     @Path("add")
     @Consumes("multipart/form-data")
     public Response add(@FormDataParam("file") final InputStream input)
     {

Or if you want the form multipart data directly use:

https://jersey.dev.java.net/nonav/apidocs/1.0.3/contribs/jersey-multipart/com/sun/jersey/multipart/FormDataMultiPart.html

For example:

     @POST
     @Path("add")
     @Consumes("multipart/form-data")
     public Response add(final FormDataMultipart parts)
     {

See the dependencies for the jersey-multipart module:

   https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.3/jersey/dependencies.html

Paul.

On Aug 12, 2009, at 8:02 PM, Jonathan Locke wrote:

>
> i am using jersey 1.0.3 and currently getting an exception when i
> try to handle multipart form data. i've tried several approaches,
> but the preferable one was:
>
> @POST
> @Path("add")
> @Consumes("multipart/form-data")
> public Response add(@FormParam("file") final InputStream input)
> {
>
> however, i never get to the method due to this exception:
>
> com.sun.jersey.api.container.ContainerException:
> javax.mail.MessagingException: Missing start boundary
> at
> com
> .sun
> .jersey
> .server
> .impl
> .model
> .method
> .dispatch
> .MultipartFormDispatchProvider
> .processForm(MultipartFormDispatchProvider.java:91)
> at
> com.sun.jersey.server.impl.model.method.dispatch.FormDispatchProvider
> $FormParameterProvider.getInjectableValues(FormDispatchProvider.java:
> 108)
> * snip *
> Caused by: javax.mail.MessagingException: Missing start boundary
> at javax.mail.internet.MimeMultipart.parsebm(MimeMultipart.java:713)
> at javax.mail.internet.MimeMultipart.parse(MimeMultipart.java:383)
>
> the HTML form i'm using to post the data is just a regular file
> upload form (i assume this is okay?):
>
> <form method="post" enctype="multipart/form-data" action="<url>/
> add">
> <input value="file" id="file" type="file">
> <p></p>
> <input type="submit" value="Upload">
> </form>
>
>