springboot如何设置请求参数长度和文件大小限制

springboot设置请求参数长度和文件大小限制

springboot yml配置方式

server:
max-http-header-size: 4048576
tomcat:
max-http-post-size: 1000MB #请求参数长度

spring:
servlet:
multipart:
enabled: true
max-file-size: 1000MB #单个文件的最大上限
max-request-size: 1000MB #单个请求的文件总大小上限

springboot文件上传时maxPostSize设置大小失效

报错信息:

Failed to 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

Caused by: java.lang.IllegalStateException: The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector

该配置尝试无效,百度说是版本问题,核对过后发现无误

servlet:
?? ?multipart:
?? ? ?enabled: true
?? ? ?max-file-size: 1000MB
?? ? ?max-request-size: 1000MB

解决办法

因为我这里上传是传图片,图片以base64形式携带在请求参数中,form表单的形式提交,故怀疑可能是请求参数大小被限制了,于是添加以下配置

#注意这是server!!不是上面的servlet,别看错了。。。
server:
? tomcat:
? ? max-http-post-size: 100MB ?#请求参数长度
?? ?max-http-form-post-size: 100MB #form表单长度

重启解决!

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
  • SpringBoot http post请求数据大小设置操作
  • SpringBoot如何通过配置文件(yml,properties)限制文件上传大小
  • 解决Springboot get请求是参数过长的情况

转载请注明出处:http://www.400tyeyaji.com/article/20230526/307152.html