文件上传时异常Processing of multipart/form-data request failed. Stream ended unexpectedly at org.apache.com

当上传文件遇到Processing of multipart/form-data request failed. Stream ended unexpectedly at org.apache.commons.fileupload.FileUploadBase.parseRequest

这个错误时,很有可能是传输数据时编码的问题。

如POST上传数据时,使用socket拼接的方式上传,POST的格式为:

POST /index.html HTTP/1.1
Connection: close
User-Agent: Macromedia Flash Player 8
X-Flash-Version: 8,0,22,0
Accept-Types: text/*
Content-Type: multipart/form-data; boundary=----------gL6Ij5ei4gL6Ef1GI3gL6gL6KM7cH2
Content-Length: 35122482
Host: localhost:4242

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

arewethereyet.mov
------------gL6Ij5ei4gL6Ef1GI3gL6gL6KM7cH2
Content-Disposition: form-data; name="Filedata"; filename="arewethereyet.mov"
Content-Type: application/octet-stream

...DATA HERE...(这里数据的编码问题,可能导致上述异常,如:文件只包含英文时无问题,包含汉字时出现此异常)
------------gL6Ij5ei4gL6Ef1GI3gL6gL6KM7cH2
Content-Disposition: form-data; name="Upload"
Submit Query
------------gL6Ij5ei4gL6Ef1GI3gL6gL6KM7cH2





你可能感兴趣的:(JavaWeb)