Fully consume input stream so that error message can be displayed in file upload

This commit is contained in:
Graham Triggs 2017-09-27 15:59:01 +01:00
parent e08a8c7715
commit 2979cdadae

View file

@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.controller;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.ArrayList; import java.util.ArrayList;
@ -190,6 +191,15 @@ public class MultipartRequestWrapper extends HttpServletRequestWrapper {
try { try {
return upload.parseRequest(req); return upload.parseRequest(req);
} catch (FileSizeLimitExceededException | SizeLimitExceededException e) { } 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()) { if (strategy.stashFileSizeException()) {
req.setAttribute(ATTRIBUTE_FILE_SIZE_EXCEPTION, e); req.setAttribute(ATTRIBUTE_FILE_SIZE_EXCEPTION, e);
return Collections.emptyList(); return Collections.emptyList();