英文:
Spring boot file multipart accept half allowed size
问题
我写了一个如下的控制器:
@PostMapping(value="/upload", produces = "application/json")
@ApiOperation("上传")
@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 approvalDetails) throws Exception{
return uploadService.uploader(file, code, approvalDetails);
}
并且我在 application.properties
中进行了以下配置:
spring.servlet.multipart.max-file-size=30MB
spring.servlet.multipart.max-request-size=30MB
但是我只能上传大约 15MB 的文件。
编辑后:
Spring Boot 版本:2.0.1
英文:
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:
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
答案1
得分: 1
1. 第一个可能的原因:
可能与您使用的 spring-boot 版本有关。
根据不同版本,MULTIPART 属性已经发生了变化。
Spring Boot 1.3.x 及更早版本:
multipart.max-file-size
multipart.max-request-size
在 Spring Boot 1.3.x 之后:
spring.http.multipart.max-file-size=-1
spring.http.multipart.max-request-size=-1
在 Spring Boot 2.0 之后:
spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1
2. 第二个可能的原因:
您的应用程序没有足够的 内存 来接收该文件。
3. 第三个可能的原因:
如果您将应用程序打包为 war 文件并部署在 tomcat 上,请确保 tomcat 允许适用于您的用例的 maxPostSize
。
在 conf\server.xml 中:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxPostSize="67589953" />
英文:
1. First potential cause:
Maybe it's related to the spring-boot version you are using.
MULTIPART properties have been changed according to versions.
Spring Boot 1.3.x and earlier
multipart.max-file-size
multipart.max-request-size
After 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.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1
2. Second potential cause:
Your app didn't have enough memory to receive the file
3. Third potential cause:
If you are packaging as war and deploying on tomcat, make sure that tomcat allows a maxPostSize
suitable for your use case.
In conf\server.xml:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxPostSize="67589953" />
答案2
得分: 0
@M.Mas.
- 我正在使用 Spring Boot 2.0.1。
- 即使我将内存减少到 8MB,也不依赖于内存,再次约为 4MB 将是可以接受的。
- 它未部署在 WAR 文件上,我正在进行调试。
我上传了一个大小为 16.8MB 的文件,导致了以下异常:
org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: 由于其大小 (33542171) 超过了配置的最大值 (31457280),请求被拒绝。
英文:
@M.Mas.
1.I'm using spring boot 2.0.1.
2.Not depends on memory even if I decrease to 8MB, again ~4MB will be acceptable.
3. It is not deployed on the WAR file and I'm debugging.
I uploaded a file with 16.8MB and it raised below exception:
> org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (33542171) exceeds the configured maximum (31457280)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论