Java文件上传报MaxUploadSizeExceededException

2019-05-27 15:07:27.077 DEBUG 1 --- [http-nio-8068-exec-2] o.s.web.servlet.DispatcherServlet        : POST "/api/doc/v1/upload", parameters={}
2019-05-27 15:07:27.077 DEBUG 1 --- [http-nio-8068-exec-2] o.s.web.servlet.DispatcherServlet        : Failed to complete request: 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 files exceeds its maximum permitted size of 1048576 bytes.
2019-05-27 15:07:27.079 ERROR 1 --- [http-nio-8068-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : 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 files exceeds its maximum permitted size of 1048576 bytes.] with root cause

org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field files exceeds its maximum permitted size of 1048576 bytes.
    at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:633) ~[tomcat-embed-core-9.0.17.jar!/:9.0.17]
    at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76) ~[tomcat-embed-core-9.0.17.jar!/:9.0.17]
    at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:135) ~[tomcat-embed-core-9.0.17.jar!/:9.0.17]
    at java.io.FilterInputStream.read(FilterInputStream.java:107) ~[na:1.8.0_181]
    at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:98) ~[tomcat-embed-core-9.0.17.jar!/:9.0.17]
    at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:68) ~[tomcat-emb

默认上传的文件最大限制1M,文件超过1M就会报错。需要在配置文件中修改这个限制。

如果Sptingboot版本为1.0,则在properties文件中加上如下配置:

# 最大支持文件大小

spring.http.multipart.max-file-size=200MB

# 最大支持请求大小

spring.http.multipart.max-request-size=200MB

如果Sptingboot版本为2.0,则在properties文件中加上如下配置:

# 最大支持文件大小

spring.servlet.multipart.max-file-size=200MB

# 最大支持请求大小

spring.servlet.multipart.max-request-size=200MB

 

你可能感兴趣的:(Java文件上传报MaxUploadSizeExceededException)