目录
  • springboot设置请求参数长度和文件大小限制
    • springboot yml配置方式
  • springboot文件上传时maxPostSize设置大小失效
    • 解决办法

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表单长度

重启解决!

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

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。