applicaton.properties配置:
spring.servlet.multipart.max-file-size=200MB
spring.servlet.multipart.max-request-size=200MB
或
application.yml配置:
# Spring配置
spring:
# 文件上传
servlet:
multipart:
# 单个文件大小
max-file-size: 20000MB
# 设置总上传的文件大小
max-request-size: 50000MB
并且添加如下配置文件
import javax.servlet.MultipartConfigElement;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;
@Configuration
public class UploadConfig {
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
//文件最大20000M
factory.setMaxFileSize(DataSize.ofMegabytes(20000));
// factory.setMaxFileSize(DataSize.parse("100MB"));
// 设置总上传数据总大小
factory.setMaxRequestSize(DataSize.parse("50000MB"));
return factory.createMultipartConfig();
}
}
网友评论