gpt4 book ai didi

spring-boot - OpenApi 使用 JSON 发送 MultipartFile 请求获取 'application/octet-stream' 错误不支持

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

我正在使用 Spring Boot,我想使用 Swagger UI 发送带有 json 的 MultipartFile 但我收到错误 'application/octet-stream' error not supported ,如果我使用 postman 工作得很好。

@RequestMapping(value = "/upload", method = RequestMethod.POST,
produces = { "application/json" },
consumes = { "multipart/form-data" })
public String hello(
@RequestPart(value = "file") MultipartFile file,
@RequestPart("grupo") Grupo grupo) {
if (file != null) {
logger.info("File name: " + file.getOriginalFilename());
}
logger.info(grupo.toString());
return grupo.toString();
}
如何解决这个问题?
  • springdoc-openapi-ui 1.4.4
  • Spring Boot 2.3.2.RELEASE
  • spring-boot-starter-web
  • Maven
  • spring-boot-starter-data-jpa
  • 最佳答案

    要使用 multipartFile 发送 json,请使用注释 @Parameter带类型 "string"和格式 "binary" ,以便您可以发送格式为 json 的文件。

    @Parameter(schema =@Schema(type = "string", format = "binary"))
    然后就会变成这个样子。
    @PostMapping(value = "/test", consumes = MediaType.MULTIPART_FORM_DATA_VALUE )
    public ResponseEntity<Void> saveDocu2ment(
    @RequestPart(value = "personDTO") @Parameter(schema =@Schema(type = "string", format = "binary")) final PersonDTO personDTO,
    @RequestPart(value = "file") final MultipartFile file) {
    return null;
    }
    引用 - Multipart Request with JSON - GitHub Springdoc openApi

    关于spring-boot - OpenApi 使用 JSON 发送 MultipartFile 请求获取 'application/octet-stream' 错误不支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63367971/

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