[英]Spring boot file multipart accept half allowed size
I wrote a controller as below:我写了一个控制器如下:
@PostMapping(value="/upload", produces = "application/json")
@ApiOperation("Upload")
@ApiIgnore
public ResponseEntity<ResponseObject> fileUpload(
@RequestParam(value="file") MultipartFile file,
@RequestParam (value="code",required=false, defaultValue="0")String code,
@RequestParam (value="approvaldetails",required=false, defaultValue="0") String approvalDeatils) throws Exception{
return uploadService.uploader(file,code,approvalDeatils);
}
and I configured below at application.porperties:我在 application.porterties 配置如下:
spring.servlet.multipart.max-file-size=30MB
spring.servlet.multipart.max-request-size=30MB
but I could able to upload file up to ~15MB Editted: Spring boot version: 2.0.1但我最多可以上传约 15MB 的文件 编辑:Spring 启动版本:2.0.1
1. First potential cause: 1.第一个潜在原因:
Maybe it's related to the spring-boot version you are using.可能和你使用的spring-boot版本有关。
MULTIPART properties have been changed according to versions. MULTIPART 属性已根据版本更改。
Spring Boot 1.3.x and earlier Spring Boot 1.3.x 及更早版本
multipart.max-file-size
multipart.max-request-size
After Spring Boot 1.3.x:在 Spring Boot 1.3.x 之后:
spring.http.multipart.max-file-size=-1
spring.http.multipart.max-request-size=-1
After Spring Boot 2.0:在 Spring Boot 2.0 之后:
spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1
2. Second potential cause: 2. 第二个潜在原因:
Your app didn't have enough memory to receive the file您的应用没有足够的内存来接收文件
3. Third potential cause: 3. 第三个潜在原因:
If you are packaging as war and deploying on tomcat, make sure that tomcat allows a maxPostSize
suitable for your use case.如果您打包为 war 并在 tomcat 上部署,请确保 tomcat 允许适合您的用例的
maxPostSize
。
In conf\\server.xml:在 conf\\server.xml 中:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxPostSize="67589953" />
@M.Mas. @M.Mas。 1.I'm using spring boot 2.0.1.
1.我使用的是spring boot 2.0.1。 2.Not depends on memory even if I decrease to 8MB, again ~4MB will be acceptable.
2.即使我减少到8MB,也不取决于内存,同样~4MB也是可以接受的。 3. It is not deployed on the WAR file and I'm debugging.
3.它没有部署在WAR文件上,我正在调试。 I uploaded a file with 16.8MB and it raised below exception:
我上传了一个 16.8MB 的文件,它引发了以下异常:
org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size ( 33542171 ) exceeds the configured maximum (31457280)
org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException:请求被拒绝,因为它的大小 ( 33542171 ) 超过了配置的最大值 (31457280)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.