7

I have to upload multiple file of type MultipartFile from swagger to test my api. Postman does allow to upload, however, same thing is not working in swagger.

Code for list of multipart file:

@ApiParam(name = "file", value = "Select the file to Upload", required = true, allowMultiple=true) 
@RequestPart(value = "file", required = true) List<MultipartFile> file

working curl command for list of multipart file:

curl -X POST "http://localhost:8080/test" -H "accept: */*" -H "Content-Type: multipart/form-data" -F "file=@example1.pdf;application/pdf;" -F "file=@example2.pdf;application/pdf;" -F "jsonString={}"

Single multipart file works in swagger as well like this:

@ApiParam(name = "file", value = "Select the file to Upload", required = true, allowMultiple=true) 
@RequestPart(value = "file", required = true) MultipartFile file

Dependency:

<!-- swagger -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>
Pati Ram Yadav
  • 815
  • 1
  • 8
  • 22

1 Answers1

0

Check this link, we cant for now...swagger dosent support this thing,check link below

https://github.com/springfox/springfox/issues/1072

,You can use postman, just select key as filetype and select multiple file.It works.

Suhas Gholap
  • 69
  • 1
  • 2