Alex Korotkov
Alex Korotkov

Reputation: 31

FileSizeLimitExceededException leads to error 500 instead of 413

I got an exception like

2018-11-01 21:05:49.122 ERROR 31446 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1024 bytes.] with root cause org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1024 bytes.

why 413 http error wasn't raised automatically?

Upvotes: 0

Views: 2617

Answers (1)

Alien
Alien

Reputation: 15878

You have to define maximum file size for a file upload.

Add below properties in application.properties

spring.http.multipart.max-file-size=128KB
spring.http.multipart.max-request-size=128KB

For spring boot 2.

spring.servlet.multipart.max-file-size=128MB
spring.servlet.multipart.max-request-size=128MB
spring.servlet.multipart.enabled=true

Refer this

Upvotes: 3

Related Questions