The field headerImage exceeds its maximum permitted size of 1048576 bytes

welcome to my blog

使用spring内置tomcat服务器上传文件失败, 报错如下, 因为默认文件大小上限为1MB

2020-03-13 20:10:36,758 ERROR [http-nio-8081-exec-7] o.a.c.c.C.[.[.[.[dispatcherServlet] [DirectJDKLog.java:175] 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.FileUploadBase$FileSizeLimitExceededException: The field headerImage exceeds its maximum permitted size of
  1048576 bytes.] with root cause
  
org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: 
The field headerImage exceeds its maximum permitted size of 1048576 bytes.

解决方法: 在application.properties中加入以下两句即可

# 上传单个文件的最大值为10MB
spring.servlet.multipart.max-file-size=10MB
# 单次请求中, 上传的所有文件总大小最大为10MB
spring.servlet.multipart.max-request-size=10MB
发布了599 篇原创文章 · 获赞 147 · 访问量 21万+

猜你喜欢

转载自blog.csdn.net/littlehaes/article/details/104848456