How to upload multiple files using swagger-ui (springfox-swagger2 and springfox-swagger-ui) and spring-boot application?
Asked Answered
R

1

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 "[email protected];application/pdf;" -F "[email protected];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>
Redroot answered 7/2, 2019 at 20:17 Comment(1)
did you find any solution?Asaasabi
P
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.

Passion answered 2/9, 2020 at 13:28 Comment(1)
Please make sure your answer is not depending entirely on links. Links may go away.Outstand

© 2022 - 2024 — McMap. All rights reserved.