OpenApi 发送带有 JSON 的 MultipartFile 请求得到 'application / octet-stream' 错误不支持
OpenApi send MultipartFile request with JSON get 'application / octet-stream' error not supported
我正在使用 Spring Boot,我想使用 Swagger json 发送 MultipartFile UI 但是我收到错误 '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 启动 2.3.2.RELEASE
- spring-boot-starter-web
- 专家
- spring-boot-starter-data-jpa
要使用 multipartFile 发送 json,请使用类型 "string"
和格式 "binary"
的注释 @Parameter
,这样您就可以发送格式为 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;
}
我正在使用 Spring Boot,我想使用 Swagger json 发送 MultipartFile UI 但是我收到错误 '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 启动 2.3.2.RELEASE
- spring-boot-starter-web
- 专家
- spring-boot-starter-data-jpa
要使用 multipartFile 发送 json,请使用类型 "string"
和格式 "binary"
的注释 @Parameter
,这样您就可以发送格式为 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;
}