我希望能够将多部分文件从一个服务传递到另一个服务。
客户端-->服务1-->服务2
当我从Service1传递文件到Service2时,会显示错误“500内部服务器错误,当前请求不是多部分请求”。
当我直接发送文件到Client-->Service2时,它可以工作,但通过Service1却不行。
我想知道可能的原因,我猜测在将多部分文件作为参数传递时,我可能错过了一些头部信息。 服务2
客户端-->服务1-->服务2
当我从Service1传递文件到Service2时,会显示错误“500内部服务器错误,当前请求不是多部分请求”。
当我直接发送文件到Client-->Service2时,它可以工作,但通过Service1却不行。
我想知道可能的原因,我猜测在将多部分文件作为参数传递时,我可能错过了一些头部信息。 服务2
@PostMapping(path="/upload")
public ResponseEntity<Properties> upload(@RequestParam("file") MultipartFile multiPart) {
return saveFile(multiPart);
}
Service2客户端
@FeignClient
(name="${feign.upload.serverId}", configuration = UploadServiceClientConfiguration.class, decode404 = true)
public interface UploadServiceClient {
@PostMapping(path="/upload")
ResponseEntity<Properties> upload(@RequestParam("file") MultipartFile multiPart);
class UploadServiceClientConfiguration {
@Value(value="${feign.upload.user}")
String user;
@Value(value="${feign.upload.password}")
String password;
@Bean
public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
return new BasicAuthRequestInterceptor(user, password);
}
}
}
服务1
@Autowired
UploadServiceClient uploadSvcClient;
@PostMapping(path="/upload")
public ResponseEntity<Properties> uploadAttachment(@RequestParam("file") MultipartFile file) {
return uploadSvcClient.upload(file);
}
@Param
而不是@RequestParam
。我已经更新了我的答案。 - Stepan Tsybulski@RequestPart
。因为根据响应,你得到的是400,告诉你服务在请求中找不到file
部分。 - Stepan Tsybulski在端口9000上运行服务器。然后,您可以将请求从服务1传递到服务2,服务2将其转发到
localhost:9000`,然后您可以分析请求中确切的内容并找出缺少什么。 - Stepan Tsybulski