简体   繁体   English

表单数据损坏:过早结束

[英]Corrupt form data: premature ending

I am trying to upload files using the FileReference class. 我正在尝试使用FileReference类上传文件。 Files >2MB all work correctly but files <2MB cause this error: 文件> 2MB都可以正常工作,但是文件<2MB会导致此错误:

"java.io.IOException: Corrupt form data: premature ending" “ java.io.IOException:表单数据已损坏:提前结束”

On the server I am using the com.oreilly.servlet package to handle the request. 在服务器上,我使用com.oreilly.servlet包来处理请求。

I have used this package many times to successfully handle file uploads from flex, but for some reason, now I am having this problem. 我已经多次使用此软件包来成功处理来自flex的文件上传,但是由于某些原因,我现在遇到了这个问题。

Here is the stack trace for some more info: 这是有关更多信息的堆栈跟踪:

java.io.IOException: Corrupt form data: premature ending
    at com.oreilly.servlet.multipart.MultipartParser.<init>(MultipartParser.java:205)
    at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:222)
    at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:173)
    at com.mydomain.FileUploadServlet.doPost(FileUploadServlet.java:46)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:414)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)

It seems that there is a bug that exists when using com.orielly.servlet.MultipartRequest class and the org.apache.struts2.dispatcher.ActionContextCleanUp filter together. 一起使用com.orielly.servlet.MultipartRequest类和org.apache.struts2.dispatcher.ActionContextCleanUp过滤器时,似乎存在一个错误。 This is what was causing small file uploads to fail. 这是导致小文件上传失败的原因。

http://www.servlets.com/cos/faq.html http://www.servlets.com/cos/faq.html

Why when using com.oreilly.servlet.MultipartRequest or MultipartParser do large uploads fail? 为什么在使用com.oreilly.servlet.MultipartRequest或MultipartParser时,大型上传失败? The classes themselves were specifically designed to have no maximum upload size limit (unlike most other file upload utilities), but for your server's protection the constructor allows you to set a maximum POST size to accept. 类本身经过专门设计,没有最大上传大小限制(与大多数其他文件上传实用程序不同),但是为了保护服务器,构造函数允许您设置要接受的最大POST大小。 Any upload larger than the limit is halted. 任何大于限制的上传都将停止。 The default maximum is 1 Meg. 默认最大值为1 Meg。 For a discussion of the difficulties a server has in notifying a client of the error, see the discussion in Java Servlet Programming, 2nd Edition, page 119. 有关服务器在通知客户端错误时遇到的困难的讨论,请参阅Java Servlet编程,第二版,第119页中的讨论。

So, did you specify the maximum POST size to accept? 那么,您是否指定了可以接受的最大POST大小?

PS Ok, now I see that it's small uploads that cause the problem. 附言:好的,现在我看到的是很小的上传量导致了问题。 On the FAQ link above there is a section dedicated to troubleshooting uploads, including some helful methods to isolate the cause (client, browser, web-server, libraries). 在上面的FAQ链接上,有一个部分专门对上载进行故障排除,包括一些隔离原因的有用方法(客户端,浏览器,Web服务器,库)。 Try them. 试试看

Install a Firefox plugin (Tamper Data or Firebug) that shows the request sent to server. 安装一个Firefox插件(篡改数据或Firebug),以显示发送到服务器的请求。 May help you to understand if anything is different between <2M and >2M uploads. 可以帮助您了解<2M和> 2M上传之间是否存在差异。

PPS Are the files of the same structure? PPS文件是否具有相同的结构? Could it be that smaller ones have different data (eg special symbols) that break Flash library? 较小的数据可能具有破坏Flash库的不同数据(例如特殊符号)吗? Try to upload small files of spaces only, for instance. 例如,尝试仅上传空间小的文件。

@Vladimir: @弗拉基米尔:

I have used an http sniffer to check the post request and it is sending the entire file and the post request format is correct. 我已使用http嗅探器检查过帐请求,并且它正在发送整个文件,并且过帐请求格式正确。 I have tried many different files (.jpg, .mp3 etc) that are <2MB and none are working. 我尝试了许多小于2MB的文件(.jpg,.mp3等),但都无法正常工作。

The maximum post size is set to 1.5GB. 最大帖子大小设置为1.5GB。

Here is what the post request is: 这是发布请求的内容:

------------cH2ae0ei4ae0cH2ae0Ef1KM7gL6GI3
Content-Disposition: form-data; name="Filename"

IMG0001.jpg
------------cH2ae0ei4ae0cH2ae0Ef1KM7gL6GI3
Content-Disposition: form-data; name="Filedata"; filename="IMG0001.jpg"
Content-Type: application/octet-stream

<file data here>
------------cH2ae0ei4ae0cH2ae0Ef1KM7gL6GI3
Content-Disposition: form-data; name="Upload"

Submit Query
------------cH2ae0ei4ae0cH2ae0Ef1KM7gL6GI3--

I have confirmed that this is a server side issue as I tested the servlet with a regular html form and I get the same results. 我已经确认这是服务器端的问题,因为我使用常规的html表单测试了servlet,并且得到了相同的结果。

Any other ideas? 还有其他想法吗?

The reason of this is because the request is been sent with a "Transfer Encoding: chunked" header, instead of a Content-length header. 这是因为请求是使用“传输编码:分块”标头而不是Content-length标头发送的。 Many servers don't understand chunked content, and neither does o'reilly. 许多服务器不了解分块的内容,o'illy也是如此。 Check with a sniffer if your request is been send with the Transfer encoding header. 用嗅探器检查您的请求是否已通过传输编码标头发送。 I don't know any solution for this. 我不知道有什么解决办法。

如果您不使用结构,则可以通过从项目库中删除结构库来解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 表格数据已损坏:阿尔卡特OT900A提前结束 - Corrupt form data: premature ending on Alcatel OT900A 如何处理java.io.IOException:表单数据损坏:com.oreilly.servlet.multipart.MultipartParser中提前结束? - How to handle java.io.IOException: Corrupt form data: premature ending occuring in com.oreilly.servlet.multipart.MultipartParser? D / skia:libjpeg错误117 - D/skia: libjpeg error 117 <Corrupt JPEG data: premature end of data 邻接矩阵的广度优先算法:搜索过早结束,返回大小为1的队列? - Breadth-first algorithm on adjacency matrix: premature ending of search, returns queue of size 1? XSLT 2.0产生损坏的数据 - XSLT 2.0 producing corrupt data Jmeter响应数据:java.io.IOException:过早的EOF - Jmeter Response data:java.io.IOException: Premature EOF 在Java JSP中读取XML数据-文件过早结束错误 - Reading XML data in Java JSP - Premature end of file error Java:Java中的UDP是否可能破坏数据 - Java: Is corrupt data possible with UDP in Java Java BlockingQueue似乎在传输期间损坏了数据 - Java BlockingQueue appears to corrupt data during transfer 序列化数据在PC上损坏,但在Android设备上未损坏 - Serialization data is corrupt on PC but not on Android device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM