通过配置文件(yml,properties)限制文件上传大小
properties类型配置文件设置
1
2
3
4
5
6
7
8
9
|
# springboot 1.X spring.http.multipart.max-file-size=50Mb spring.http.multipart.max-request-size=50Mb # springboot 2.X spring.servlet.multipart.max-file-size=50Mb spring.servlet.multipart.max-request-size=50Mb |
yml类型配置文件设置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
## springboot 1.X spring: http: multipart: enabled: true max-file-size: 50MB max-request-size: 50MB ## springboot 2.X spring: servlet: multipart: enabled: true max-file-size: 50MB max-request-size: 50MB |
设置文件上传大小限制--默认为1M
SpringBoot默认上传文件大小不能超过1MB
超过之后会报以下异常:
org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.
解决方法
请在配置文件(application.properties/application.yml)中加入如下设置即可
低版本: 1.X
1
2
|
spring.http.multipart.max-file-size=10MB spring.http.multipart.max-request-size=10MB |
高版本: 2.X
1
2
|
spring.servlet.multipart.max-file-size=30Mb spring.servlet.multipart.max-request-size=30Mb |
或者
1
2
|
spring.servlet.multipart.maxFileSize=10MB spring.servlet.multipart.maxRequestSize=20MB |
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_31183727/article/details/100925226