在前端上传大小超过1M的文件时,报了个异常。
后来发现是spring boot有默认的上传文件大小限制。为1M,对应属性为multipart.maxFileSize。在配置文件里增加如下配置即可:
需要设置以下两个参数
multipart.maxFileSize
multipart.maxRequestSize
application.yml中设置如下
multipart: maxFileSize: 10485760 maxRequestSize: 10485760
application.properties中设置如下:
Spring Boot 1.3.x 或者之前
multipart.maxFileSize=100Mb multipart.maxRequestSize=1000Mb
Spring Boot 1.4.x 或者之后
spring.http.multipart.maxFileSize=100Mb spring.http.multipart.maxRequestSize=1000Mb
很多人设置了multipart.maxFileSize但是不起作用,是因为1.4版本以上的配置改了,详见官方文档:spring boot 1.4