gpt4 book ai didi

spring-mvc - 如何在 Spring Boot 中使用没有 Content-Disposition header 的 multipart/form-data 处理 POST

转载 作者:行者123 更新时间:2023-12-04 12:17:09 25 4
gpt4 key购买 nike

我正在使用 Sprin Boot,我需要处理这种类型的请求:

POST /post HTTP/1.0
content-type: multipart/form-data;boundary=482CFA229C8C00EBE48F4FAE633EDB4A0
content-length: 157
x-numbercomps: 1
user-agent: SAP NetWeaver Application Server (1.0;750)
host: 172.0.0.1:8080
accept-encoding: gzip

--482CFA229C8C00EBE48F4FAE633EDB4A0
Content-Type: text/plain
Content-Length: 11
X-compId: test.txt

content
--482CFA229C8C00EBE48F4FAE633EDB4A0--

Controller :
@PostMapping(value = "/**", params = {"create"}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String createPost(HttpServletRequest request,
@RequestParam MultipartFile... files) {
//do some staff

return "";
}

在 Controller 中没有错误,但MuiltipartFiles的数量为0

没有 Content-Disposition Spring 无法识别 MultipartFile。

任何人有任何想法如何处理它?

谢谢。

最佳答案

我使用了你的 Controller 并发布了多个文件,似乎没有问题并检查了所有标题,但没有 Content-Disposition在我的标题中,但我可以看到所有文件的详细信息。似乎问题是发送请求而不是 Spring 启动端。

请看下面的截图:

Multipart file request

这是我收到的标题,没有 Content-Disposition
Headers

关于spring-mvc - 如何在 Spring Boot 中使用没有 Content-Disposition header 的 multipart/form-data 处理 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52438807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com