" MIMEParsingException:缺少起始边界"仅在Chrome浏览器中发生异常,Firefox在Jersey fileUpload期间正常运行

时间:2014-04-05 18:56:30

标签: google-chrome file-upload jersey multipartform-data mozilla

仅供参考,我的应用程序类路径中包含以下球衣罐以及mimepull jar版本:

jersey-apache-client-1.11.jar
jersey-apache-client4-1.11.jar
jersey-client-1.17.1.jar
jersey-core-1.17.1.jar
jersey-guice-1.17.1.jar
jersey-json-1.17.1.jar
jersey-multipart-1.17.1.jar
jersey-server-1.17.1.jar
jersey-servlet-1.11.jar
mimepull-1.6.jar

我甚至尝试过将它们全部用于1.11或1.17.1作为球衣特定的罐子。当我尝试通过最新的Chrome浏览器提交文件上传请求时(这是客户端html代码提交文件上传):

<form name="uploadFile" action="/app/fileUpload" method="post" enctype="multipart/form-data">
<input type="file" name="file" class="input-file"/><br/>
<button type="submit" id="upload-btn" class="btn btn-primary">Upload</button>
</form>

奇怪的是,我的文件上传泽西资源甚至没有被击中,我的Chrome浏览器出现400错误,但我的服务器日志中出现以下异常,但它在我的Firefox浏览器中运行良好:

[toResponse] WebApplicationExceptionMapper status='400' message='org.jvnet.mimepull.MIMEParsingException: Missing start boundary' url='/app/fileUpload'
    javax.ws.rs.WebApplicationException: org.jvnet.mimepull.MIMEParsingException: Missing start boundary
        at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(MultiPartReaderClientSide.java:146)
        at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(MultiPartReaderClientSide.java:82)
        at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:488)
        at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:552)
        at com.sun.jersey.multipart.impl.FormDataMultiPartDispatchProvider$FormDataInjectableValuesProvider.getInjectableValues(FormDataMultiPartDispatchProvider.java:122)
        at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)
        at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:203)
        at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
        at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
        at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
        at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
        at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
        at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
        at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    ...
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
        at java.lang.Thread.run(Thread.java:724)
    Caused by: org.jvnet.mimepull.MIMEParsingException: Missing start boundary
        at org.jvnet.mimepull.MIMEParser.skipPreamble(MIMEParser.java:306)
        at org.jvnet.mimepull.MIMEParser.access$300(MIMEParser.java:67)
        at org.jvnet.mimepull.MIMEParser$MIMEEventIterator.next(MIMEParser.java:143)
        at org.jvnet.mimepull.MIMEParser$MIMEEventIterator.next(MIMEParser.java:128)
        at org.jvnet.mimepull.MIMEMessage.makeProgress(MIMEMessage.java:198)
        at org.jvnet.mimepull.MIMEMessage.parseAll(MIMEMessage.java:181)
        at org.jvnet.mimepull.MIMEMessage.getAttachments(MIMEMessage.java:106)
        at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readMultiPart(MultiPartReaderClientSide.java:187)
        at com.sun.jersey.multipart.impl.MultiPartReaderServerSide.readMultiPart(MultiPartReaderServerSide.java:80)
        at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(MultiPartReaderClientSide.java:144)
        ... 46 more

这是请求有效负载,与Firefox有效负载相比也看起来正确,我不明白为什么我在Chrome浏览器中看到400个相同请求但在Firefox中看到200OK

  Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryNkIU5AivMR0pDmZG
   Host:localhost:8080
   Origin:http://localhost:8080
   Referer:http://localhost:8080/app/files
   User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36
   Request Payload
   ------WebKitFormBoundaryNkIU5AivMR0pDmZG
   Content-Disposition: form-data; name="file"; filename="file.zip"
   Content-Type: application/zip


   ------WebKitFormBoundaryNkIU5AivMR0pDmZG--

任何有关解决此错误的指示都将受到高度赞赏。如果您需要我方提供更多信息,请告知我们以进一步了解该问题。

这是Jersey资源方法签名:

@POST
@Path("/fileUpload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadMultiPartFormData(@FormDataParam("file") InputStream file_in,
@FormDataParam("file")FormDataContentDisposition fileName) throws Exception {

0 个答案:

没有答案