使用 Springfox 和 Swagger-ui 上传的多部分文件上传不起作用

Multipart File upload using Springfox and Swagger-ui upload is not working

我正在使用 Spring Boot 2.6.4 和 Spring Fox 3.0.0,我有一个分段文件上传,但没有出现上传按钮。

@PostMapping(consumes = "multipart/form-data")
public ResponseEntity<Object> addDocument(@RequestPart (value = "files", required = true) MultipartFile[] multipartFiles)
        throws NoSuchAlgorithmException, IOException {

这是它在 Swagger 上的显示方式。是否可以使用按钮上传?

您是否尝试在方法中包含参数类型?例如:

@PostMapping(consumes = "multipart/form-data")
public ResponseEntity<Object> addDocument(
    @Parameter(
        description = "Files to be uploaded", 
        content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA_VALUE)
    )
    @RequestPart (value = "files", required = true) MultipartFile[] multipartFiles)
        throws NoSuchAlgorithmException, IOException {

写得不错! ¯_(ツ)_/¯

尝试将MultipartFile用作RequestParam, (@RequestParam("attachments") MultipartFile[] attachments)

@PostMapping(consumes = "multipart/form-data")
public ResponseEntity<Object> addDocument(@RequestParam ("files") MultipartFile[] multipartFiles) throws IOException {

}

_