SpringBoot项目上传大文件报错

SpringBoot项目默认允许上传文件的大小为1M,当超过1M时程序会报错,如下:

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.

确认如下三个方面的配置:

1、添加或修改application.properties 中的下面两个配置

spring.http.multipart.maxFileSize=10Mb
spring.http.multipart.maxRequestSize=100Mb

2、修改nginx配置

nginx配置文件的http、server、location段分别将client_max_body_size尽量设置大一些,如100m

3、修改tomcat的server.xml配置,添加或者修改 maxPostSize 配置

connectionTimeout="20000" URIEncoding="UTF-8"
redirectPort="8443" maxPostSize="100000000"/>

然后重启服务即可。

你可能感兴趣的:(SpringBoot)