Multipart file maximum size exception - spring boot embbeded tomcat

后端 未结 6 1267
说谎
说谎 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:38

    The below code worked for me. Add it to spring boot main class:

    import javax.servlet.MultipartConfigElement;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.web.servlet.MultipartConfigFactory;
    import org.springframework.context.annotation.Bean;
    import org.springframework.scheduling.annotation.EnableAsync;
    import org.springframework.scheduling.annotation.EnableScheduling;
    
    
    
    @SpringBootApplication
    @EnableScheduling
    @EnableAsync
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
        
        @Bean
        MultipartConfigElement multipartConfigElement() {
            MultipartConfigFactory factory = new MultipartConfigFactory();
            factory.setMaxFileSize("5MB");
            factory.setMaxRequestSize("5MB");
            return factory.createMultipartConfig();
        }
    }
    

提交回复
热议问题