Fully consume input stream so that error message can be displayed in file upload
This commit is contained in:
parent
e08a8c7715
commit
2979cdadae
1 changed files with 10 additions and 0 deletions
|
@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.controller;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
|
@ -190,6 +191,15 @@ public class MultipartRequestWrapper extends HttpServletRequestWrapper {
|
|||
try {
|
||||
return upload.parseRequest(req);
|
||||
} catch (FileSizeLimitExceededException | SizeLimitExceededException e) {
|
||||
// Fully consume input stream, so that error message is displayed
|
||||
try {
|
||||
InputStream in = req.getInputStream();
|
||||
byte[] buffer = new byte[4096];
|
||||
while (in.read(buffer) != -1) ;
|
||||
} catch (IOException ioe) {
|
||||
// Ignore any errors at this point
|
||||
}
|
||||
|
||||
if (strategy.stashFileSizeException()) {
|
||||
req.setAttribute(ATTRIBUTE_FILE_SIZE_EXCEPTION, e);
|
||||
return Collections.emptyList();
|
||||
|
|
Loading…
Add table
Reference in a new issue