美文网首页
spring boot报FileSizeLimitExceede

spring boot报FileSizeLimitExceede

作者: 大数据Zone | 来源:发表于2020-12-07 14:52 被阅读0次

开发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报FileSizeLimitExceede

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