I have set max file size to
multipart.maxFileSize: 1mb
multipart.maxRequestSize: 1mb
This is my controller :
@RequestMapping(method=RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(HttpStatus.CREATED)
@Secured(Privileges.CAN_USER_READ)
public void create(@RequestParam("file")final MultipartFile file,Principal principal) throws IllegalStateException, IOException,MultipartException{
medicalHistoryService.create(new MedicalHistory(file));
}
this is error message
2016-03-03 13:48:24.560 WARN 4992 --- [nio-8080-exec-1] h.c.w.RestResponseEntityExceptionHandler : Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (9288401) exceeds the configured maximum (1048576)
2016-03-03 13:48:25.545 WARN 4992 --- [nio-8080-exec-2] h.c.w.RestResponseEntityExceptionHandler : Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (9288401) exceeds the configured maximum (1048576)
And final result after request with over-sized file is problem loading page. I dont get any other error in stack trace so i am kinda stuck with what is actually going on. Oh yeah i have tried many other solutions such as registering filter, handling exception in ErrorController. Every time i would end up with same result - server crash.
EDIT 2
My exception handling class :
@ControllerAdvice
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler{
// 413 MultipartException - file size too big
@ExceptionHandler({MultipartException.class,FileSizeLimitExceededException.class,java.lang.IllegalStateException.class})
public ResponseEntity<Object> handleSizeExceededException(final WebRequest request, final MultipartException ex) {
//log.warn("413 Status Code. File size too large {}", ex.getMessage());
log.warn(ex.getMessage());
final ApiError apiError = message(HttpStatus.PAYLOAD_TOO_LARGE, ex);
return handleExceptionInternal(ex, apiError, new HttpHeaders(), HttpStatus.PAYLOAD_TOO_LARGE, request);
}
}
handleExceptionInternal
do, for example. A minimal, complete, verifiable example will make it easier for people to help you. – BridgeshandleExceptionInternal
is internal method ofResponseEntityExceptionHandler
which is, by documentation " A convenient base class for {@link ControllerAdvice @ControllerAdvice} classes * that wish to provide centralized exception handling". – Teenyweeny