我正在尝试使用 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\"])",
然后通过参考这个link https://github.com/OpenFeign/feign-form#spring-multipartfile-and-spring-cloud-netflix-feignclient-support.我在我的客户端尝试了以下代码。
public class MultipartSupportConfig {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters;
@Bean
public Encoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
}
然后通过代码示例,我将我的多部分文件对象更改为文件对象。现在我的请求被触发,但我得到了Not a multipart request
.
我试过这个https://github.com/pcan/feign-client-test#feign-client-test https://github.com/pcan/feign-client-test#feign-client-test,
我创建了一个类并使用了编码器类,并将编码器更改为 FeignSpringFormEncoder,
我仍然收到“未找到序列化器”错误。
任何人都可以使用 feign cleint 共享一个简单的客户端、带有多部分文件请求数组的服务器示例。谢谢!