如何配置Spring Boot中请求参数长度及文件上传大小限制?

2026-05-25 21:211阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计414个文字,预计阅读时间需要2分钟。

如何配置Spring Boot中请求参数长度及文件上传大小限制?

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

目录
  • 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

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

如何配置Spring Boot中请求参数长度及文件上传大小限制?

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

重启解决!

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

本文共计414个文字,预计阅读时间需要2分钟。

如何配置Spring Boot中请求参数长度及文件上传大小限制?

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

目录
  • 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

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

如何配置Spring Boot中请求参数长度及文件上传大小限制?

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

重启解决!

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