OpenApi使用JSON GET/OCTET-STREAM发送多部分文件请求错误不受支持 [英] OpenApi send MultipartFile request with JSON get 'application / octet-stream' error not supported
本文介绍了OpenApi使用JSON GET/OCTET-STREAM发送多部分文件请求错误不受支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Spring Boot,并且我希望使用Swagger UI使用json发送多部分文件,但如果我使用Postman工作得很好,则收到错误'application/octet-stream' error not supported
。
@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();
}
如何解决此问题?
- Spring-Openapi-UI 1.4.4
- Spring Boot 2.3.2版本
- Spring-Boot-starter-web
- Maven
- Spring-boot-starter-data-jpa
推荐答案
若要发送包含多部分文件的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;
}
参考-Multipart Request with JSON - GitHub Springdoc openApi
这篇关于OpenApi使用JSON GET/OCTET-STREAM发送多部分文件请求错误不受支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文