Home > Software design >  Multipart File upload using Springfox and Swagger-ui upload is not working
Multipart File upload using Springfox and Swagger-ui upload is not working

Time:03-19

I am using Spring Boot 2.6.4 and Spring Fox 3.0.0, I have a multipart file upload, but it is not appearing the button for uploading.

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

Here is how it appears on Swagger. Is it possible to use the button for uploading?

enter image description here

CodePudding user response:

Did you try to include the type of parameter in the method? eg:

@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 {

good coding! ¯_(ツ)_/¯

CodePudding user response:

Try to use MultipartFile as a RequestParam. (@RequestParam("attachments") MultipartFile[] attachments)

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

}

_

enter image description here

  • Related