問題:
一個 springboot項目經過測試時,在文本框上傳時傳入大文本(大約5M的文字),系統報錯:
The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector
根據上述文字可知,post的parameter data大小過大導致報錯,
於是查了一下Tomcat不同版本的maxPostSize的設置
Solution:
修改Spring Boot內置Tomcat的maxPostsize值,在application.yml配置文件中添加以下內容:
server:
tomcat:
max-http-post-size: -1
ps:不同類型項目同時注意大文件上傳可能涉及到的其他問題
1. 修改前端框架上傳控件jQuery Uploadify的上傳文件限制大小
2. Spring MVC框架配置的文件上傳模塊中的MultipartResolver中的文件上傳限制大小,
spring:
servlet:
multipart:
max-file-size: 30Mb
max-request-size: 100Mb
3. 修改Nginx服務器中conf目錄下的nginx.conf配置文件中的client_max_body_size屬性
4. Tomcat服務器中conf目錄下的server.xml配置文件中的connectionTimeout屬性、maxPostSize屬性。
5. 修改數據庫中最大允許數據包默認配置值。
Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (16800061 > 16777216). You can change this value on the server by setting the max_allowed_packet’ variable.
Solution:
修改DB的max_allowed_packet值:
USE demo;
set global max_allowed_packet = 3*1024*1024*10; # 改爲30M
show VARIABLES like '%max_allowed_packet%'; # 重啓DB連接生效
Note:MySQL中max_allowed_packet 的 默認配置:16777216 = 16 * 1024 * 1024,即16M
6.涉及到得幾個參數應該協調
memory_limit > post_max_size >= upload_max_filesize