spring-boot - 如何使用 swagger-ui(springfox-swagger2 和 springfox-swagger-ui)和 spring-boot 应用程序上传多个文件?

标签 spring-boot swagger-ui swagger-2.0 springfox

我必须从 swagger 上传 MultipartFile 类型的多个文件来测试我的 api。 postman 确实允许上传,但是,同样的事情在 swagger 中不起作用。

多部分文件列表的代码:

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

用于多部分文件列表的工作 curl 命令:
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={}"

单个多部分文件也可以像这样在 swagger 中工作:
@ApiParam(name = "file", value = "Select the file to Upload", required = true, allowMultiple=true) 
@RequestPart(value = "file", required = true) MultipartFile file

依赖:
<!-- 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>

最佳答案

检查这个链接,我们现在不能......大摇大摆不支持这个东西,检查下面的链接
https://github.com/springfox/springfox/issues/1072
,您可以使用 postman ,只需选择 key 作为文件类型并选择多个文件即可。它有效。

关于spring-boot - 如何使用 swagger-ui(springfox-swagger2 和 springfox-swagger-ui)和 spring-boot 应用程序上传多个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54581598/

相关文章:

mysql - JPA - 如何使 JSON POST 请求中不需要字段

spring-boot - 带有 Spring Boot 的简单嵌入式 Kafka 测试示例

rest - Thymeleaf 与 Spring MVC + Swagger

swagger-ui - Swagger UI 是否有路径的永久链接?

c# - Swashbuckle - 在 swagger 文档中将字符串视为枚举

php - 如何将 ref 用于示例 Swagger?

java - 在 Spring Boot 中重定向到不同的主机(非 www 到 www URL)

java - JPA 不想在 Spring Boot 中创建表

node.js - 在 Node js 中使用多个 api 文档来 Swagger ?

objective-c - 如何将 Swagger 规范中的 bool 数据类型映射到 Objective C 客户端 SDK 中的 NSNumber?