最近用到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數據大小