From 8d9a360fddfab500adc4c2d338428a85e4cf1c7c Mon Sep 17 00:00:00 2001 From: Michael Menzel Date: Tue, 4 Jun 2019 12:56:01 +0200 Subject: [PATCH] Setting tomcat max file size and added error redirect on too large file --- .../spring/controller/ApplicationController.java | 14 ++++++++++++++ frontend/src/main/resources/application.properties | 1 + 2 files changed, 15 insertions(+) diff --git a/frontend/src/main/java/de/thm/spring/controller/ApplicationController.java b/frontend/src/main/java/de/thm/spring/controller/ApplicationController.java index 1a86efbb..15e7b711 100644 --- a/frontend/src/main/java/de/thm/spring/controller/ApplicationController.java +++ b/frontend/src/main/java/de/thm/spring/controller/ApplicationController.java @@ -26,8 +26,12 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.multipart.MultipartException; +import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; import javax.servlet.RequestDispatcher; import javax.servlet.http.HttpServletRequest; @@ -112,6 +116,16 @@ public class ApplicationController implements ErrorController { return "error"; } + @ControllerAdvice + public class FileErrorController extends ResponseEntityExceptionHandler { + + @ExceptionHandler(MultipartException.class) + String handleFileException(HttpServletRequest request, Throwable ex, Model model) { + model.addAttribute("errorMessage", "The file you tried to upload is too large. Please upload only files with a max. file size of 20 MB."); + return "error"; + } + } + @RequestMapping("/faq") public String faq(){ diff --git a/frontend/src/main/resources/application.properties b/frontend/src/main/resources/application.properties index 4330489f..97b621ee 100644 --- a/frontend/src/main/resources/application.properties +++ b/frontend/src/main/resources/application.properties @@ -5,5 +5,6 @@ logging.level.org.hibernate=INFO spring.mvc.favicon.enabled = false spring.servlet.multipart.max-file-size=20MB spring.servlet.multipart.max-request-size=20MB +server.tomcat.max-swallow-size=20971520 #management.security.enabled=false \ No newline at end of file -- GitLab