OpenAPI 3.x 中的文件最好用application/octet-stream
.
我使用以下方法解决了这个问题
@Operation( // Swagger/OpenAPI 3.x annotation to describe the endpoint
summary = "Small summary of the end-point",
description = "A detailed description of the end-point"
)
@PostMapping(
value = "/uploads",
consumes = {MediaType.MULTIPART_FORM_DATA_VALUE} // Note the consumes in the mapping
)
public void uploadMultipleFiles (
// ------------ Multipart Object ------------
@Parameter(description = "Additional request data") // Swagger/OpenAPI annotation
@RequestParam("req") RequestDTO request, // Spring annotation
// ------------ File uploads go next ------------
@Parameter(
description = "Files to be uploaded",
content = @Content(mediaType = MediaType.APPLICATION_OCTET_STREAM_VALUE) // Won't work without OCTET_STREAM as the mediaType.
)
@RequestParam("files") List<MultipartFile> files // Spring annotation
)
有关 OpenAPI 3 规范中文件上传的更多详细信息,请参见此处