spring boot报FileSizeLimitExceededException异常的解决方法

编程知识 更新时间:2023-04-05 03:46:25

开发spring boot程序时,遇到了如下错误:
The field file exceeds its maximum permitted size of 1048576 bytes.

原因:
Spring Boot工程嵌入的tomcat限制了请求的文件大小,官方文档中这样描述:

Spring Boot embraces the Servlet 3 javax.servlet.http.Part API to support uploading files. By default Spring Boot configures Spring MVC with a maximum file of 1Mb per file and a maximum of 10Mb of file data in a single request.

翻译一下:每个文件的最大为1Mb,单次请求的文件的总数不能大于10Mb。

解决方法:
spring boot 2.0 之后,在配置文件application.yaml或 application.properties中增加如下配置:

spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=1000MB

如果想不让文件大小受限,将spring.servlet.multipart.max-file-size这个参数设置成-1。

更多推荐

spring boot报FileSizeLimitExceededException异常的解决方法

本文发布于:2023-04-05 03:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/aaaa4be48d526f1cf024764f74dad202.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:解决方法   异常   spring   boot   FileSizeLimitExceededException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 44591文章数
  • 14阅读数
  • 0评论数