如何在Spring feign客户端中将多个图像作为@RequestPart传递?

问题描述 投票:0回答:1

我正在尝试使用 feign 客户端传递多个文件(图像)。但是,当我对 MultipartFile 列表或数组使用 @RequestPart 注释时,出现错误。对于单个 MultipartFile 它工作得很好。

假客户端方法:

    
    @ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = FileInfo.class) })
    @PostMapping(
            value = "/upload-multi-files",
            produces = { "application/json" },
            consumes = { "multipart/form-data" }
    )
    ResponseEntity<FileInfo> uploadMultiFiles(@NotNull @Valid @RequestPart(value = "images", required = true) List<MultipartFile> images);

当我从代码中调用它时,出现以下错误:

feign.codec.EncodeException: Could not write request: no suitable HttpMessageConverter found for request type [java.util.ArrayList] and content type [multipart/form-data]
    at org.springframework.cloud.openfeign.support.SpringEncoder.encode(SpringEncoder.java:143) ~[spring-cloud-openfeign-core-2.1.0.RELEASE.jar:2.1.0.RELEASE]
    at feign.ReflectiveFeign$BuildEncodedTemplateFromArgs.resolve(ReflectiveFeign.java:372) ~[feign-core-10.1.0.jar:?]
    at feign.ReflectiveFeign$BuildTemplateByResolvingArgs.create(ReflectiveFeign.java:224) ~[feign-core-10.1.0.jar:?]
    ...

如何使其与列表或数组一起使用?

java spring spring-cloud-feign
1个回答
0
投票

使用此参数类型“MultipartFile[]”替换“List”

© www.soinside.com 2019 - 2024. All rights reserved.