users@jersey.java.net

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

From: Jonathan Locke <jonathan.locke_at_gmail.com>
Date: Thu, 13 Aug 2009 08:41:42 -0700

<dependency>

<groupId>javax.mail</groupId>

<artifactId>mail</artifactId>

<version>1.4</version>

</dependency>


On Wed, Aug 12, 2009 at 1:50 PM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:

>
> On Aug 12, 2009, at 10:45 PM, Paul Sandoz wrote:
>
> Hi,
>
>
> The log presents an empty multipart message (the -- on the end signals that
> and t is
> correct) and then i rechecked your form and there is an issue, you need to use:
>
> <form action="<url>/addl"
> method="POST" enctype="multipart/form-data">
> <input type="file" name="file" />
> <input type="submit" name="submit" value="upload" />
> </form>
>
>
> I should have also said i cannot reproduce your error when i use the same
> HTML form you previously presented. Perhaps it is a JavaMail version
> difference? what version are you using?
>
> Paul.
>
> I have attached a simple maven project that exercises forms using the
> jersey-multipart module and JavaMail.
>
> Paul.
>
> <fileupload.zp>
>
>
> On Aug 12, 2009, at 10:17 PM, Jonathan Locke wrote:
>
> thanks for the speedy response!
>
> output is below. it looks like the boundary is two characters different
> (the -- on the end). i'm using safari on a macbook pro, but also have the
> same problem with firefox.
>
> 1 * In-bound request received
> 1 > POST http://localhost:7979/services/rest/probeprocessor/csv/v1/add/
> 1 > Content-Length: 44
> 1 > Accept-Encoding: gzip, deflate
> 1 > Referer: http://localhost:7979/debug/home.0
> 1 > Connection: keep-alive
> 1 > Accept-Language: en-us
> 1 > Host: localhost:7979
> 1 > User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us)
> AppleWebKit/530.19.2 (KHTML, like Gecko) Version/4.0.2 Safari/530.19
> 1 > Origin: http://localhost:7979
> 1 > Content-Type: multipart/form-data;
> boundary=----WebKitFormBoundary5Kzj3IivAxrpF7Qn
> 1 > Cookie: JSESSIONID=1w8232e2jko9l
> 1 > Accept:
> application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> 1 >
> ------WebKitFormBoundary5Kzj3IivAxrpF7Qn--
>
> ERROR - log - Nested in
> javax.servlet.ServletException:
> com.sun.jersey.api.container.ContainerException:
> javax.mail.MessagingException: Missing start boundary:
> 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)
>
>
>
>
> On Wed, Aug 12, 2009 at 12:40 PM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
>
>> 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>
>>
>>
>>
>>
>
>
>