问题描述
上传文件时,SpringMVC报错:
org.springframework.web.multipart.MultipartException: Current request is not a multipart request
来到项目配置,发现上传文件限制在5M,但上传的图片只有1M+,所以SpringMVC并不会拦截该文件上传。
#文件上传大小限制
http:
multipart:
max-file-size: 5MB
注:SringBoot配置文件上传大小配置
properties配置方式:
spring.http.multipart.max-file-size=xxMB
yum配置方式:
spring:
http:
multipart:
max-file-size:xxMB
检查Nginx配置
$ vim /etc/nginx/nginx.conf
找到http
节点下的client_max_body_size
配置为1M。
也有可能没有配置该项,但默认值同样很小。

加大该项配置但值,如10M,保存并重启服务器。
$ nginx -s reload
再次上传图片,成功!
网友评论