Does anyone know of a workaround whereby if you are trying to flush the servlet output stream, apache commons fileupload throws the following exception?
FileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
Basically I have code that loops through each file uploaded using apache commons fileupload, and then am trying to out.flush()
some stats about each file. ie:
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(request);
for(FileItem field : items) {
if (!field.isFormField() && field.getName().length()>0 && field.getName().getSize()>0) {
ArticleImport helper = new ArticleImport(new ArticleImportResponder(user,out));
// This helper object uses out.flush() to provide feedback to the user.
helper.process(field.getInputStream(), user);
}
}
}
The problem does not occur in Apache Tomcat 6.0.20, but it does occur in earlier versions.