SpringBoot 文件上传失败,超出限制大小

SpringBoot 文件上传失败,超出限制大小,第1张

最近在SpringBoot项目中,使用上传功能时,报错如下:

[2022-04-25 15:20:18:956] [ERROR] [http-nio-9092-exec-9] - com.xxxxx.xxx.drs.common.GlobalExceptionHandler.globalExceptionHandler(GlobalExceptionHandler.java:43) - Controller-ERROR Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.a
pache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field file exceeds its maximum permitted
size of 1048576 bytes.

显示文件的大小超出了允许的范围,查看了官方文档。原来Spring Boot工程嵌入的tomcat限制了请求的文件大小,这一点在Spring Boot的官方文档中有说明,原文如下:

文档说明表示,每个文件的配置最大为1Mb,单次请求的文件的总数不能大于10Mb。要更改这个默认值需要在配置文件(如application.properties)中加入两个配置:

#如果是想要不限制文件上传的大小,那么就把两个值都设置为-1就行啦
#单个文件大小,默认1MB
spring.servlet.multipart.max-file-size: 1MB
#单次请求的文件总大小,默认10MB
spring.servlet.multipart.max-request-size: 10MB

具体配置如下:

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/738491.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-28
下一篇 2022-04-28

发表评论

登录后才能评论

评论列表(0条)

保存