From 2979cdadae3208f2faf0f5c6ff3414acfb590d7f Mon Sep 17 00:00:00 2001 From: Graham Triggs Date: Wed, 27 Sep 2017 15:59:01 +0100 Subject: [PATCH] Fully consume input stream so that error message can be displayed in file upload --- .../webapp/controller/MultipartRequestWrapper.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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();