注:SpringBoot1.x和2.x对上传文件大小的配置是不一样的。2.x的解决办法请看最后。
问题描述(SpringBoot1.x)
前两天写文件上传,接口写好后测试了一下,上传了一个大约15MB的文件,报错org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (16190292) exceeds the configured maximum (10485760)
于是研究了一下这个问题。找了一些资料。发现SpringBoot处理请求和文件上传时由于文件大小限制会报以下两个问题:
-
1.请求超过10MB:
org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (16190292) exceeds the configured maximum (10485760)
注:10485760 = 10 * 1024 * 1024 = 10MB -
2.上传的文件超过1MB但请求总体大小未超过10MB:
org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.
注:1048576 = 1 * 1024 * 1024 = 1MB。也就是说,即使请求总体大小小于10MB,而某个文件的大小超过1