<
>

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

2022-09-30 16:10:29 来源:易采站长站 作者:

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

目录
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 as编程sociated 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表单长度

重启解决!

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

暂时禁止评论

微信扫一扫

易采站长站微信账号