首页 > 文章列表 > springboot上传文件太大报错怎么解决

springboot上传文件太大报错怎么解决

springboot
319 2023-05-18

1、springboot 2.1.0 上传文件太大报错

Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (216185201) exceeds the configured maximum (104857600)

2、处理方案:

1.查看Nginx 能否有限制请求数据大小

server {

        listen       80;

        #server_name  localhost;

      client_max_body_size 500M;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

location /test/ {

    proxy_pass   http://127.0.0.1:8080/test/;

        }

}

其中: client_max_body_size 500M;必需打开,放开限制

3.查看tomcat能否有限制请求数据大小

在D:Program FilesApache Software FoundationTomcat 8.5confserver.xml

<Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               maxPostSize="-1"

               redirectPort="8443" />

maxPostSize 设置请求大小,-1代表不限制

4.springboot 设置请求大小限制

在application.properties配置:

spring.servlet.multipart.max-file-size=500MB

spring.servlet.multipart.max-request-size=500MB