You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Postman上传Excel到Spring Boot时报“Current Request is not a multipart request”错误

问题根因及解决方案

1. 核心配置错误(最主要原因)

你当前application.properties中关闭了Spring Boot的multipart请求自动解析功能:

spring.http.multipart.enabled=false

这是Spring Boot 1.x版本的旧配置属性,且enabled=false会直接禁用multipart请求的解析能力,自然会抛出非multipart请求的错误。

修复方式:

删除上述配置行,或者替换为Spring Boot 2.x+的正确配置:

# 启用multipart解析,默认就是true,可不写
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=2MB
spring.servlet.multipart.max-request-size=2MB

2. 表单参数名不匹配

你的控制器接口要求接收名为file的文件参数(@RequestPart("file") MultipartFile file),但你提供的curl请求中form表单的参数名为空:

# 错误写法,参数名未声明为file
--form '=@"/C:/Users/srika/Documents/Git_Repos/abc-100-abc-xyz-00-Team/resources/PlayerList.xlsx"'

修复方式:

curl请求修改为:

curl --location --request POST 'http://localhost:9090/player/upload/5' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzcmlrYXJrIiwiZXhwIjoxNjM1NzEzMDAwLCJpYXQiOjE2MzU2MjY2MDB9._GcCznGiiWE4fRRkaRfhc7El9ETEOhbzL6ErhPsU_aY' \
--form 'file=@"/C:/Users/srika/Documents/Git_Repos/abc-100-abc-xyz-00-Team/resources/PlayerList.xlsx"'

Postman中同步修改:form-data标签下的KEY列填写file,再选择对应的Excel文件。

3. 可选校验

确认Postman的Headers标签中没有手动添加Content-Type: multipart/form-data,该请求头会由Postman自动生成并携带正确的boundary参数,手动添加反而会导致解析失败。

内容的提问来源于stack exchange,提问作者KGP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 08:09:01