上传文件文件过大时出现如下错误:
org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field pic exceeds its maximum permitted size of 10485760 bytes.
因为springboot内置tomact的的文件传输默认为10MB
需要在application.properties中配置:
#配置文件传输
spring.servlet.multipart.enabled =true
spring.servlet.multipart.file-size-threshold =0
#单个数据的大小
spring.servlet.multipart.max-file-size = 100Mb
#总数据的大小
spring.servlet.multipart.max-request-size=100Mb
spring.servlet.multipart.enabled =true
注意:必需要开启置为true。如果是想要不限制文件上传的大小,那么就把两个值都设置为-1
在线文件大小(bit,bytes,KB,MB,GB,TB)转换换算: http://www.bejson.com/convert/filesize/
Spring Boot 1.3.x
multipart.maxFileSize
multipart.maxRequestSize
Spring Boot 1.4.x and 1.5.x
spring.http.multipart.maxFileSize
spring.http.multipart.maxRequestSize
Spring Boot 2.x
spring.servlet.multipart.maxFileSize
spring.servlet.multipart.maxRequestSize
下面是2.x的示例
# Single file max size spring: servlet: multipart: max-file-size: 10MB max-request-size: 100MB