问题描述
- A服务(服务提供者)提供文件下载接口
- B服务(服务消费者)通过Feign请求拿到文件
服务提供者A
@GetMapping(value = "/file/{fileName}")
public void downFile(@PathVariable("fileName") String fileName, HttpServletResponse response) {
}
服务消费者B
@FeignClient("consume-file")
public interface FileFeignClient {
@GetMapping(value = "/file/{fileName}")
Response downFile(@PathVariable("fileName") String fileName);
}
private final FileFeignClient fileFeignClient;
@GetMapping(value = "down/{fileName}")
public void down(@PathVariable("fileName") String fileName, HttpServletResponse response){
Response responseFile = fileFeignClient.downFile(fileName);
InputStream inputStream = responseFile.body().asInputStream();
IOUtils.copy(inputStream,response.getOutputStream());
}