多部分文件 api 不支持的媒体类型

格式

POSTMAN 总是错误地给出 415 不受支持的媒体类型。标题包含具有边界的多部分/表单数据,如下面的 CURL 调用。还尝试用 RequestBody 替换 RequestPart 没有成功。

在使用 FilePart 时,我们是否需要以任何不同的方式从 spring 5 调用多部分文件上传 apis?

REST控制器:

 @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public void uploads(@RequestPart("filePart") Flux<Part> fileparts) {

     ....

}

卷曲:

curl -X POST \
  http://localhost:8080/upload \
  -H 'accept: application/json' \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -H 'postman-token: 2e850843-13d0-32d3-8734-227242da3303' \
  -F [email protected]

输出:

"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'text/plain' not supported",

编辑

将上传参数从 更改@RequestPart("filePart") Flux<Part> fileparts@RequestParam("file") MultipartFile file然而有效。

我们不能对 RequestPart 使用相同的 curl 调用吗?

格式

问题是由于 pom.xml 将 spring-webmvc 和 spring-webflux 添加为依赖项。这似乎spring-webmvcspring-webflux不能启用在一起。

 <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>${spring.boot.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
        <version>${spring.boot.version}</version>
    </dependency>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Boot-多部分-不支持的媒体类型

Spring WebFlux文件上传:不支持分段上传的415类型媒体

Spring MVC Ajax文件上传导致415(不支持的媒体类型)

iPhone:AVAudioPlayer不支持的文件类型

调用Web API 2端点时HTTP 415不支持的媒体类型错误

Django REST Framework文件上传导致“不支持的媒体类型'multipart / form-data'”错误

Youtube api:badContent:不支持媒体类型“ application / mp4”。有效的媒体类型:[视频/ *,应用程序/八位位流]

在Java中上传Excel文件时,如何解决错误415不支持的媒体类型错误?

远程服务器返回错误:(415)在asp.net中使用API的不支持的媒体类型

如何在Angular 6中上传文件时修复415不支持的媒体类型

无法通过其余管理API创建Keycloak领域:不支持的媒体类型

使用邮递员测试.Net Web API时得到415不支持的媒体类型

尝试使用Rest API创建Hpalm缺陷时,获取“ 415不支持的媒体类型”

错误415在上传文件中不支持的媒体类型

出现错误415-提取API中不支持的媒体类型

Angular 7和.NET Core API中不支持的媒体类型415错误

设置无gRPC DB-DB API网关:415不支持的媒体类型

“ Application / vnd.api + json”引发“不支持的媒体类型”

Web API ASP.NET Core发布请求415不支持的媒体类型

在Spotify API的授权过程中获取HTTP 415不支持的媒体类型

带有多部分请求的Spring Boot不支持的媒体类型

将整数列表发送到REST API会抛出415(不支持的媒体类型)

上载时Web API不支持的媒体类型-未传递字符集

球衣RESTful api在使用FormDataMultipart时答复415不支持的媒体类型

计算机视觉 ocr API 返回 http 响应:Java http 请求不支持的媒体类型

Forge Api PATCH 请求返回 415“不支持的媒体类型”

Perl:连接到 Walmart API 以加载项目不支持的媒体类型错误

在 web api 中使用数组作为参数时不支持的媒体类型错误?

请求中不支持的媒体类型“text/plain;charset=UTF-8”。NextJS API 错误与 Django Rest Framework