Corrupt form data: premature ending

后端 未结 5 2007
清酒与你
清酒与你 2020-12-10 10:14

I am trying to upload files using the FileReference class. Files >2MB all work correctly but files <2MB cause this error:

\"java.io.IOException: Co

相关标签:
5条回答
  • 2020-12-10 10:29

    The reason of this is because the request is been sent with a "Transfer Encoding: chunked" header, instead of a Content-length header. Many servers don't understand chunked content, and neither does o'reilly. Check with a sniffer if your request is been send with the Transfer encoding header. I don't know any solution for this.

    0 讨论(0)
  • 2020-12-10 10:39

    If you are not using structs then it can be solved by deleting the structs libraries from your project's library .

    0 讨论(0)
  • 2020-12-10 10:40

    @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. I have tried many different files (.jpg, .mp3 etc) that are <2MB and none are working.

    The maximum post size is set to 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.

    Any other ideas?

    0 讨论(0)
  • 2020-12-10 10:49

    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. This is what was causing small file uploads to fail.

    0 讨论(0)
  • 2020-12-10 10:52

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

    Why when using com.oreilly.servlet.MultipartRequest or MultipartParser do large uploads fail? 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. Any upload larger than the limit is halted. The default maximum is 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.

    So, did you specify the maximum POST size to accept?

    P.S. 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). Try them.

    Install a Firefox plugin (Tamper Data or Firebug) that shows the request sent to server. May help you to understand if anything is different between <2M and >2M uploads.

    P.P.S. Are the files of the same structure? Could it be that smaller ones have different data (e.g. special symbols) that break Flash library? Try to upload small files of spaces only, for instance.

    0 讨论(0)
提交回复
热议问题