上传大文件时出现以下错误:多部分请求包含的参数数据(不包括上传的文件)超过了关联连接器上设置的maxPostSize限制]
我有以下application.properties(我也尝试将这些设置为-1,即无限制)
spring.servlet.multipart.max-file-size=250MB
spring.servlet.multipart.max-request-size=250MB
server.tomcat.max-http-form-post-size=250000000
server.tomcat.max-swallow-size=250000000
在主应用程序类中,Application.java:
/* Configures the embedded Tomcat max post size */
@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> containerCustomizer() {
return (TomcatServletWebServerFactory container) -> {
String propVal = environment.getProperty("spring.servlet.multipart.max-request-size");
int postSize = 10000000; // Default - 10MB
if (!propVal.isEmpty()) {
postSize = Integer.parseInt(propVal.substring(0, propVal.length() - 2));
if (propVal.endsWith("KB")) {
postSize = postSize * 1000;
}
else if (propVal.endsWith("MB")) {
postSize = postSize * 1000000;
}
}
// Needs to be final for lambda expression bellow
final int maxPostSize = postSize;
container.addConnectorCustomizers((connector) -> connector.setMaxPostSize(maxPostSize));
};
}
然而,我仍然得到错误。有人可能有任何建议或想法吗?
Spring Boot版本=2.6.6,Tomcat版本=Apache Tomcat/9.0.62
简单,在application.properties
# What you want
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=20MB