参考springboot最大上传文件配置
package com.ustcinfo.fn.config;
import org.springframework.beans.factory.annotation.Value;
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;
import javax.servlet.MultipartConfigElement;
/**
* @author Jamin
* @date 2020/11/12 17:54
*/
@Configuration
public class TomcatConfig {
@Value("${spring.server.MaxFileSize}")
private String maxFileSize;
@Value("${spring.server.MaxRequestSize}")
private String maxRequestSize;
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
// 单个数据大小
factory.setMaxFileSize(DataSize.parse(maxFileSize));
/// 总上传数据大小
factory.setMaxRequestSize(DataSize.parse(maxRequestSize));
return factory.createMultipartConfig();
}
}
#文件上传限制默认10m
# 无用spring.servlet.multipart.max-file-size
spring.server.MaxFileSize=104857600
spring.server.MaxRequestSize=104857600