【问题标题】:How to send List of List of MultiPartFile through postman如何通过邮递员发送 MultiPartFile 列表列表
【发布时间】:2021-08-12 18:36:43
【问题描述】:

我有这个 API 方法

public ResponseEntity<ApiResponse> createProducts(@RequestPart @Valid ProductRequest productRequest, @RequestPart List<List<MultipartFile>> imageList) { }

现在我想通过邮递员发送 imageList 我该如何发送

【问题讨论】:

  • 我想这应该是public ResponseEntity&lt;ApiResponse&gt; createProducts(@RequestPart @Valid ProductRequest productRequest, @RequestPart List&lt;MultipartFile&gt; imageList1, @RequestPart List&lt;MultipartFile&gt; imageList2) { }。如果您不知道 imageList 的数量,则需要从 HttpRequest 获取部件
  • @grekier 问题是我不知道它没有固定的数字
  • 你能告诉我如何使用 HttpRequest

标签: java spring-boot postman


【解决方案1】:

我猜你需要类似的东西:

public ResponseEntity<ApiResponse> createProducts(HttpServletRequest request) {
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    Set set = multipartRequest.getFileMap().entrySet();
    Iterator i = set.iterator();
    while (i.hasNext()) {
        Map.Entry me = (Map.Entry)i.next();
        // me.getKey() will give you the parameter name
        // me.getValue() will give you the data (List<MultipartFile> probably)
        // handle files ...
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-14
    • 2020-12-24
    • 2017-07-20
    • 2015-05-27
    • 2019-01-20
    • 2023-02-20
    • 2017-07-03
    • 2020-10-25
    相关资源
    最近更新 更多