多文件上传中遇到上传文件大小的问题
org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field fileName exceeds its maximum permitted size of 1048576 bytes.
Spring Boot默认文件上传大小为2M,多文档上传中总是出现文件大小超出限度
解决方法:
a、在application.properties文件中设置文件大小
# Single file max size
multipart.maxFileSize=50Mb
# All files max size
multipart.maxRequestSize=50Mb
但是,事实证明此种方法不能够解决以上问题
b、在启动类App.class文件中配置Bean来设置文件大小
import javax.servlet.MultipartConfigElement; 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.context.annotation.Configuration; /** * Hello world! * */ @SpringBootApplication @Configuration public class App { public static void main( String[] args ) { System.out.println( "Hello World!" ); SpringApplication.run(App.class, args); } /** * 文件上传配置 * @return */ @Bean public MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); //单个文件最大 factory.setMaxFileSize("10240KB"); //KB,MB /// 设置总上传数据总大小 factory.setMaxRequestSize("102400KB"); return factory.createMultipartConfig(); }
}