views:

3159

answers:

5

I am trying to upload files using the FileReference class. Files >2MB all work correctly but files <2MB cause this error: "java.io.IOException: Corrupt form data: premature ending"

On the server I am using the com.oreilly.servlet package to handle the request.

I have used this package many times to successfully handle file uploads from flex, but for some reason, now I am having this problem.

Any ideas?

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)


Update:

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.

A: 
Vladimir Dyuzhev
A: 

@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?

maclema
A: 

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.

A: 

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.

maclema
A: 

how do u resolve this bug?

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.

donno