Java – Why did I get “FileUploadException: Stream ended unexpectedly” with Apache Commons FileUpload


What is the reason for encountering this Exception:

  Processing of multipart/form-data request failed. Stream ended unexpectedly

Best Solution

The main reason is that the underlying socket was closed or reset. The most common reason is that the user closed the browser before the file was fully uploaded. Or the Internet was interrupted during the upload. In any case, the server side code should be able to handle this exception gracefully.