I have done some research around this with conflicting results. To handle this error, some say that I need to implement HandlerExceptionResolver
in one of my controllers.
Here are some links for that:
On the other hand, other people are saying that this approach is futile such that the Exception
is occuring outside the request handling flow:
I have tried the above solutions but they do not work for me. It appears that the Exception
occurs outside of Spring, as expected. I am unable to catch this even with HandlerExceptionResolver
.
Handling MaxUploadSizeExceededException In order to handle this exception, we can have our controller implement the interface HandlerExceptionResolver, or we can create a @ControllerAdvice annotated class.
You are using method getSize() of MultipartFile, which I think returns size in bytes in binary. So convert that to in MB you have to multiply file. getSize() with 0.00000095367432 . This will give you size in MB.
The default is 1MB. max-request-size specifies the maximum size allowed for multipart/form-data requests. The default is 10MB. file-size-threshold specifies the size threshold after which files will be written to disk.
Trying following the approach specified in the link below. Basically, you configure an error page for any un handled exception and then define a handler for the error page. Looks like a decent workaround.
Here is the link http://www.javacodegeeks.com/2013/11/how-to-custom-error-pages-in-tomcat-with-spring-mvc.html
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With