版权声明:转载请声明原文出处!!!! https://blog.csdn.net/weixin_40461281/article/details/82343779
解决SpringBoot2.0 The field file exceeds its maximum permitted size of 1048576 bytes 报错问题
在使用SpringBoot进行文件上传时出现了这个问题,是因为SpringBoot自带集成的Tomcat限制了文件上传大小,需要在application.yml配置文件中重新设置
注意不同的SpringBoot版本设置文件大小限制的方式不一样,有些配置属性因为SpringBoot版本的迭代已经不能使用了.
SpringBoot 2.0配置文件大小:
spring:
servlet:
multipart:
enabled: true
max-file-size: 10Mb
max-request-size: 100Mb
SpringBoot1.5.9版本
spring:
http:
multipart:
enabled: true
max-file-size: 10Mb
max-request-size: 100Mb
也可以编写配置bean
/**
* 文件上传配置
* @return
*/
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
//单个文件最大
factory.setMaxFileSize("10MB"); //KB,MB
//设置总上传数据总大小
factory.setMaxRequestSize("100MB");
return factory.createMultipartConfig();
}