多部分文件超出限制异常
Multipart File Exceed Limit Exception
我正在使用 SPring 启动来开发我的系统,但在上传超过 1MB 的文件(使用多部分文件类型)时出现此异常。谁能给我解释一下?谢谢
java.lang.IllegalStateException: Multipart Mime part file exceeds max filesize
at org.eclipse.jetty.util.MultiPartInputStreamParser$MultiPart.write(MultiPartInputStreamParser.java:111) ~[jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.util.MultiPartInputStreamParser.parse(MultiPartInputStreamParser.java:681) ~[jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.util.MultiPartInputStreamParser.getParts(MultiPartInputStreamParser.java:400) ~[jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.Request.getParts(Request.java:2146) ~[jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.Request.extractMultipartParameters(Request.java:386) ~[jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.Request.extractContentParameters(Request.java:309) ~[jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.Request.extractParameters(Request.java:257) ~[jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.Request.getParameter(Request.java:826) ~[jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:70) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) ~[jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) ~[jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:103) ~[spring-boot-actuator-1.3.1.RELEASE.jar:1.3.1.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) ~[jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]
at vn.com.splussoftware.sms.config.OAuth2AuthenticationFilter.doFilter(OAuth2AuthenticationFilter.java:71) ~[bin/:na]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) ~[jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585) [jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577) [jetty-security-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) [jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.Server.handle(Server.java:499) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.io.AbstractConnection.run(AbstractConnection.java:544) [jetty-io-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) [jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:555) [jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_66]
在 application.properties
文件中配置文件上传。将单个多部分文件和整个请求(可以包含多个文件)的限制设置为 3 MB (Spring Boot 2.x):
spring.servlet.multipart.max-file-size: 3MB
spring.servlet.multipart.max-request-size: 3MB
默认值是:
spring.servlet.multipart.max-file-size: 1MB
spring.servlet.multipart.max-request-size: 10MB
在节点中
<servlet> .... <multipart-config>
<location>/tmp</location>
<max-file-size>1000000000</max-file-size>
<max-request-size>1500000000</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
属性 文件中的内容发生了一些变化。
spring:
http:
multipart:
maxFileSize: 20MB
maxRequestSize: 20MB
在spring(https://spring.io/guides/gs/uploading-files/)的文档中建议放入src/main/resources/application.properties
:
spring.servlet.multipart.max-file-size=100Mb
spring.servlet.multipart.max-request-size=100Mb
对我有用!
对于 Spring Boot 2,application.yml
文件将如下所示:
spring:
servlet:
multipart:
enabled: true
max-file-size: 20MB
max-request-size: 20MB
不限制文件大小和请求大小
Spring 引导 1.5.x:
spring.http.multipart.max-file-size=-1
spring.http.multipart.max-request-size=-1
Spring 启动 2.0.x:
spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1
我正在使用 SPring 启动来开发我的系统,但在上传超过 1MB 的文件(使用多部分文件类型)时出现此异常。谁能给我解释一下?谢谢
java.lang.IllegalStateException: Multipart Mime part file exceeds max filesize at org.eclipse.jetty.util.MultiPartInputStreamParser$MultiPart.write(MultiPartInputStreamParser.java:111) ~[jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.util.MultiPartInputStreamParser.parse(MultiPartInputStreamParser.java:681) ~[jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.util.MultiPartInputStreamParser.getParts(MultiPartInputStreamParser.java:400) ~[jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.Request.getParts(Request.java:2146) ~[jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.Request.extractMultipartParameters(Request.java:386) ~[jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.Request.extractContentParameters(Request.java:309) ~[jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.Request.extractParameters(Request.java:257) ~[jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.Request.getParameter(Request.java:826) ~[jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:70) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) ~[jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) ~[jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106] at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:103) ~[spring-boot-actuator-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) ~[jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106] at vn.com.splussoftware.sms.config.OAuth2AuthenticationFilter.doFilter(OAuth2AuthenticationFilter.java:71) ~[bin/:na] at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) ~[jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585) [jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577) [jetty-security-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) [jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.Server.handle(Server.java:499) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.io.AbstractConnection.run(AbstractConnection.java:544) [jetty-io-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) [jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106] at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:555) [jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106] at java.lang.Thread.run(Unknown Source) [na:1.8.0_66]
在 application.properties
文件中配置文件上传。将单个多部分文件和整个请求(可以包含多个文件)的限制设置为 3 MB (Spring Boot 2.x):
spring.servlet.multipart.max-file-size: 3MB
spring.servlet.multipart.max-request-size: 3MB
默认值是:
spring.servlet.multipart.max-file-size: 1MB
spring.servlet.multipart.max-request-size: 10MB
在节点中
<servlet> .... <multipart-config>
<location>/tmp</location>
<max-file-size>1000000000</max-file-size>
<max-request-size>1500000000</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
属性 文件中的内容发生了一些变化。
spring:
http:
multipart:
maxFileSize: 20MB
maxRequestSize: 20MB
在spring(https://spring.io/guides/gs/uploading-files/)的文档中建议放入src/main/resources/application.properties
:
spring.servlet.multipart.max-file-size=100Mb
spring.servlet.multipart.max-request-size=100Mb
对我有用!
对于 Spring Boot 2,application.yml
文件将如下所示:
spring:
servlet:
multipart:
enabled: true
max-file-size: 20MB
max-request-size: 20MB
不限制文件大小和请求大小
Spring 引导 1.5.x:
spring.http.multipart.max-file-size=-1
spring.http.multipart.max-request-size=-1
Spring 启动 2.0.x:
spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1