Multipart file maximum size exception - spring boot embbeded tomcat

This was tricky. Tomcat property MaxSwallowSize was causing this problem. Apparently it was introduced in one of the recent versions of Tomcat. The whole idea behind it was if Tomcat realized the request was going to be rejected, to terminate the connection anything higher than default 2mb (at least this was my interpretation). Simple overriding this property fixes things. I realize this is not perfect solution, but it is a whole lot better than just terminating connection.

@Bean
public TomcatEmbeddedServletContainerFactory containerFactory() {
    TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
     factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
        @Override
        public void customize(Connector connector) {
         ((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
        }
     });
     return factory;
}

Started from Spring Boot 2

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

See docs

Spring Boot 1.x

Properties should like:
spring.http.multipart.max-file-size=128KB
spring.http.multipart.max-request-size=128KB

See spring boot guides


Please add the below lines in application.properties for spring boot version -2.0.1.RELEASE

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

This resolved my issue.