spring boot 2 上传文件大小限制的配置不生效解决方式

上传文件文件过大时出现如下错误:

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
  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 14
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZhaoYingChao88

整理不易,还请多多支持,谢谢

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值