How to set the max size of upload file

前端 未结 16 671
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 12:13

I\'m developing application based on Spring Boot and AngularJS using JHipster. My question is how to set max size of uploading files?

If I\'m trying

16条回答
  •  粉色の甜心
    2020-12-04 12:24

    None of the configuration above worked for me with a Spring application.

    Implementing this code in the main application class (the one annotated with @SpringBootApplication) did the trick.

    @Bean 
    EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
         return (ConfigurableEmbeddedServletContainer container) -> {
    
                  if (container instanceof TomcatEmbeddedServletContainerFactory) {
    
                      TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
                      tomcat.addConnectorCustomizers(
                              (connector) -> {
                                  connector.setMaxPostSize(10000000);//10MB
                              }
                      );
                  }
        };
    }
    

    You can change the accepted size in the statement:

    connector.setMaxPostSize(10000000);//10MB

提交回复
热议问题