美文网首页
SpringBoot上传文件大小限制的配置

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

作者: 一只有思想的小蚂蚁 | 来源:发表于2020-11-17 15:14 被阅读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

相关文章

网友评论

      本文标题:SpringBoot上传文件大小限制的配置

      本文链接:https://www.haomeiwen.com/subject/xewxiktx.html