【发布时间】:2018-08-24 13:52:00
【问题描述】:
我正在尝试使用 springboot 制作一个简单的上传应用程序,它可以正常工作,直到我尝试上传 10Mb+ 文件,我在屏幕上收到此消息:
There was an unexpected error (type=Internal Server Error, status=500).
Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (14326061) exceeds the configured maximum (10485760)
我进行了一些研究,但到目前为止没有任何效果。我将把到目前为止我尝试过的事情留在这里。
将此代码(以各种方式)放在我的“application.yml”中
multipart:
maxFileSize: 51200KB
maxRequestFile: 51200KB
我也在我的主要课程中尝试过这个:
@Bean
public TomcatEmbeddedServletContainerFactory containerFactory() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
}
});
return factory;
}
还有一些奇怪的事情。如果我输入我的 tomcat web.xml,multipart-config 是:
<multipart-config>
<!-- 50MB max -->
<max-file-size>52428800</max-file-size>
<max-request-size>52428800</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
那么这个“...配置的最大值(10485760)”到底是从哪里来的呢? (旁注:我使用的是 netbeans 8.1 和 springboot 1.5)。
谢谢伙计们。(对于英语 s2 感到抱歉)
既然问了,这是我的application.yml
server:
port: 9999
context-path: /client
logging:
level:
org.springframework.security: DEBUG
endpoints:
trace:
sensitive: false
spring:
thymeleaf:
cache: false
multipart:
maxFileSize: 51200KB
maxRequestFile: 51200KB
#################################################################################
security:
basic:
enabled: false
oauth2:
client:
client-id: acme2
client-secret: acmesecret2
access-token-uri: http://localhost:8080/oauth/token
user-authorization-uri: http://localhost:8080/oauth/authorize
resource:
user-info-uri: http://localhost:8080/me
#
【问题讨论】:
-
尝试使用
spring.servlet.multipart.max-file-size=51200KB和spring.servlet.multipart.max-request-size=51200KB -
感谢您的回复。我试过“spring.servlet”但没有成功。而且我认为它没有重复,因为该问题中的解决方案没有解决我的问题。
-
能否提供
application.yml文件 -
@Rahul Mahadik 我刚刚添加了我的 application.yml。即使在“spring.http”中,这也不起作用......
标签: java spring-boot upload