Multipart file maximum size exception - spring boot embbeded tomcat

后端 未结 6 1273
说谎
说谎 2021-01-04 20:03

I have set max file size to

multipart.maxFileSize: 1mb
multipart.maxRequestSize: 1mb

This is my controller :

@RequestMappi         


        
6条回答
  •  情歌与酒
    2021-01-04 20:49

    Since @SeaBiscuit has provided the correct answer but with Spring boot 2.0.0.RELEASE the class org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory has been removed and replaced by the class org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory. So the code for the new Spring boot 2.0.0 would be

    1. Create a class with any name and annotate it with @Configuration
    2. And put the below code inside that class
    @Bean
    public TomcatServletWebServerFactory containerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
            @Override
            public void customize(Connector connector) {
                ((AbstractHttp11Protocol) connector.getProtocolHandler()).setMaxSwallowSize(-1);
            }
        });
        return factory;
    }
    

    And if you've trouble configuring the maximum file upload size in Spring boot 2.0.0 put below code inside 'application.propertise' file with desired file size in 'MB's

    ## Image upload limitation properties
    spring.servlet.multipart.max-file-size=3MB
    spring.servlet.multipart.max-request-size=3MB
    

提交回复
热议问题