问题
I'm working on multiple file upload. Having strange issue when uploading multiple files.
Case: When I select multiple files, if one of file size is big compare to other its not submitted to servlet. I'm selecting below files(Image). I used breakpoint and went to step by step and found that error.txt
's size is 0Bytes
in servlet. If I upload this by selecting as single its uploading properly.
Having same issue with other file when its big, its not specific to error.txt. I just gave you the case
FYI: I'm using gwtupload
plugin for multiple upload. Here is the link of project : https://code.google.com/p/gwtupload
Update:
@Manolo Why you used cont
variable in servlet?
int cont = 0;
for (FileItem item : sessionFiles) {
if (false == item.isFormField()) {
cont ++;
回答1:
After tons of try I found the solution so let me show you where I made mistake in code.
for (FileItem item : sessionFiles) {
if (false == item.isFormField()) {
try {
/// Create a temporary file placed in the default system temp folder
File file = File.createTempFile("upload-", ".bin");
item.write(file);
/// Save a list with the received files
receivedFiles.put(item.getFieldName(), file);
receivedContentTypes.put(item.getFieldName(), item.getContentType());
/// Send a customized message to the client.
response += "File saved as " + file.getAbsolutePath();
// Below line is creating the problem.
removeItem(request, item.getFieldName());
} catch (Exception e) {
throw new UploadActionException(e);
}
}
}
I'm removing each file using removeItem(request, item.getFieldName());
after processing it. Somehow its removing the error.txt
file. I don't know why. But after removing that line. It worked for me.
来源:https://stackoverflow.com/questions/19248675/servlet-receives-0bytes-of-file