spring boot项目上传文件

严重: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is 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 uploadfile exceeds its maximum permitted size of 1048576 bytes.] with root cause
org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field uploadfile exceeds its maximum permitted size of 1048576 bytes.

 

解决方案呢,要根据SpringBoot的版本来确定,以下列举出了几种情况,可以根据自己项目的SpringBoot版本来对应:把默认的文件的大小限制修改一下即可。以下是我项目中的用到的文件大小限制,改成50MB即可满足我的需求了。

3.1 SpringBoot 1.3.x 之前
multipart.maxFileSize=50Mb
multipart.maxRequestSize=50Mb
3.2 SpringBoot 1.4.x
spring.http.multipart.maxFileSize=50Mb
spring.http.multipart.maxRequestSize=50Mb
3.3 SpringBoot 2.0.x之后
spring.servlet.multipart.max-file-size=50MB

————————————————
版权声明:本文为CSDN博主「No8g攻城狮」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_44299027/article/details/126074192

posted @ 2023-04-21 15:36  moonsoft  阅读(43)  评论(0编辑  收藏  举报