报错内容:
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException: the request was rejected because its size (39353107) exceeds the configured maximum (10485760)
解决方案:
一 application.yml 添加配置 :
spring: servlet: multipart: max-request-size: 100MB max-file-size: 100MB
二 Application启动类添加bean:
@Bean public MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); //单个文件最大 factory.setMaxFileSize(DataSize.parse("5MB")); /// 设置总上传数据总大小 factory.setMaxRequestSize(DataSize.parse("20MB")); return factory.createMultipartConfig(); }