2

我正在尝试使用 feign 客户端上传多部分文件对象数组。这是我尝试使用 Feign 客户端调用的服务。

public ResponseEntity<Object> manageFileUpload(@RequestParam("files") MultipartFile[] files)

我尝试使用,Feign 客户端注解,

@FeignClient(value = "UPLOADUTILITIES", configuration = Upload.MultipartSupportConfig.class, fallback = UploadFallback.class)

我的方法,

@RequestMapping(name = "upload", value = "/object", method = RequestMethod.POST)
@Headers("Content-Type: multipart/form-data")
ResponseEntity<Object> manageFileUpload(@Param("files") MultipartFile[] files);

我因错误而得到回报,

"message": "Type definition error: [simple type, class java.io.FileDescriptor]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class java.io.FileDescriptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile[0]->org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile[\"inputStream\"]->java.io.FileInputStream[\"fd\"])",

然后通过引用此链接。我在客户端尝试了打击代码。

public class MultipartSupportConfig {

    @Autowired
    private ObjectFactory<HttpMessageConverters> messageConverters;

    @Bean
    public Encoder feignFormEncoder() {
        return new SpringFormEncoder(new SpringEncoder(messageConverters));
    }
}

然后通过代码示例,我将 MultiPart File 对象更改为 File Object。现在我的请求被触发了,但我得到了Not a multipart request.

我试过这个https://github.com/pcan/feign-client-test#feign-client-test

我创建了一个类并使用了编码器类,并将我的编码器更改为 FeignSpringFormEncoder,

我仍然收到 No serializer found 错误。

任何人都可以使用 feign cleint 与 Array of Multipart 文件请求共享一个简单的客户端、服务器示例。谢谢!

4

0 回答 0