最近用到springboot项目,通过base64转字符串上传图片,遇到问题,报如下错误:
org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:111)
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:85)
看了这个错误,感觉是springboot内置的tomcat给限制了,于是在application
配置文件添加如下参数:
以1.5.4为例,设置单个文件大小为50M限制,总上传的数据大小为100M,如下:
spring.http.multipart.max-file-size=50MB
spring.http.multipart.max-request-size=100MB
再以2.0.1为例,设置单个文件大小为10M限制,总上传的数据大小也为100M,如下:
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=100MB
配置完以后结果又报另一个错:
java.lang.IllegalStateException: The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector
从网上找到修改Spring Boot内置Tomcat的maxPostsize
值,那就在application.properties中加上这句话:
server.tomcat.max-http-post-size=0
server.maxHttpHeaderSize=102400000 //设定HttpHeader请求头大小
server.maxHttpPostSize =102400000 //设定Httppost数据大小