方法一
spring:
servlet:
multipart:
max-file-size: 20MB
max-request-size: 20MB
方法二
在扫描包下添加如下类,然后再application.yml 添加配置
import javax.servlet.MultipartConfigElement;
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;
@Configuration
public class FileUploadConfig {
/**
* 文件上传配置
*
* @return MultipartConfigElement
*/
@Bean
public MultipartConfigElement multipartConfigElement(
@Value("${multipart.maxFileSize}") String maxFileSize,
@Value("${multipart.maxRequestSize}") String maxRequestSize) {
MultipartConfigFactory factory = new MultipartConfigFactory();
// 单个文件最大
factory.setMaxFileSize(maxFileSize);
// 设置总上传数据总大小
factory.setMaxRequestSize(maxRequestSize);
return factory.createMultipartConfig();
}
}
multipart:
maxFileSize: 5Mb
maxRequestSize: 500Mb