SpringBoot上传文件大小限制的配置

2020-11-17  本文已影响0人  一只有思想的小蚂蚁

使用SpingBoot框架上传文件时,如果文件大小超过了1MB,会报错:

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

原因是SpringBoot内置的Tomcat的文件传输默认单个文件最大1M,单次请求文件总数大小为10M。
解决方法:
可以在SpingBoot的application.yml配置文件中进行修改

SpingBoot2.0版本之前:

spring:
  http:
    multipart:
      maxFileSize: 20MB  #单个文件最大为20M
      maxRequestSize: 20MB #单次请求文件总数大小为20M

SpingBoot2.0版本之后:

spring:
  servlet:
    multipart:
      max-file-size: 20MB #单个文件最大为20M
      max-request-size: 20MB #单次请求文件总数大小为20M
上一篇 下一篇

猜你喜欢

热点阅读