spring boot通过xml文件限制指定路径上传文件大小
时间: 2023-07-30 18:10:08 浏览: 71
可以通过在 Spring Boot 的 application.properties 或 application.yml 配置文件中添加以下属性来限制指定路径上传文件大小:
application.properties:
```
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
```
application.yml:
```
spring:
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
```
其中,max-file-size 表示单个文件的最大大小,max-request-size 表示请求中所有文件的最大总大小。这两个属性都支持 KB、MB 和 GB 等单位。
如果要对指定的路径进行文件上传大小限制,则需要在配置文件中指定对应的路径,例如:
```
spring.mvc.servlet.load-on-startup=1
spring.mvc.servlet.multipart.enabled=true
spring.mvc.servlet.multipart.file-size-threshold=5MB
spring.mvc.servlet.multipart.location=${java.io.tmpdir}
spring.mvc.servlet.multipart.max-file-size=10MB
spring.mvc.servlet.multipart.max-request-size=10MB
spring.mvc.servlet.multipart.resolve-lazily=true
spring.mvc.servlet.multipart.multipart-configurations.fileupload.path=/upload/**
spring.mvc.servlet.multipart.multipart-configurations.fileupload.max-file-size=1MB
spring.mvc.servlet.multipart.multipart-configurations.fileupload.max-request-size=2MB
```
其中,path 表示需要限制上传文件大小的路径,max-file-size 和 max-request-size 表示该路径下上传文件的最大大小和请求中所有文件的最大总大小。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)