diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/MultipartRequestWrapper.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/MultipartRequestWrapper.java index 2e3773b22..d5439df6c 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/MultipartRequestWrapper.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/controller/MultipartRequestWrapper.java @@ -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();