最近項目中用到了文件圖片上傳操作,
前端 使用<input type="file" class="ignore" accept="image/jpeg,image/png,image/gif"> (base64字節)
后台使用String字符串進行接收(base64字節)
properties配置文件中進行文件上傳大小配置
spring.http.multipart.max-file-size=20Mb //上傳文件的大小限定;只有上傳采用文件格式進行接收時起作用,針對上面的base64格式圖片(后台是String進行接收)不起作用;
spring.http.multipart.max-request-size=60Mb //上傳請求數據的大小限定;限定請求的總數據大小
但是發現當上傳文件大小大於1.5M時就會報錯:
2018-06-08 11:03:19.006 ERROR 3784 --- [nio-8080-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector] with root cause java.lang.IllegalStateException: The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector
經過分析發現是springboot中的內置tomcat服務器限定了Httppost的最大size
通過在properties中添加如下配置,修改該內置服務器的對HttpPost數據的大小; 成功解決該問題;
server.maxHttpHeaderSize=102400000 //設定HttpHeader請求頭大小
server.maxHttpPostSize =102400000 //設定Httppost數據大小