SpringBoot默认上传文件大小不能超过1MB,超过之后会报以下异常:
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.
解决方法:
请在配置文件(application.properties/application.yml)中加入如下设置即可
1、Spring Boot 1.3 版本:
multipart.maxFileSize=10Mb
2、Spring Boot 1.4 版本和 1.5 版本:
spring.http.multipart.maxFileSize=10Mb
spring.http.multipart.maxRequestSize=100Mb
3、Spring Boot 2.0 版本:
spring.servlet.multipart.max-file-size=10485760
spring.servlet.multipart.max-request-size=10485760
附 application.yml 配置示例:
spring:
servlet:
multipart:
enabled: true
max-file-size: -1