Feign下载文件 [英] Feign for downloading file

查看:192
本文介绍了Feign下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种简单的方法来使用 Feign 下载 csv 文件(保留文件名).

I am trying to find a simple way to use Feign to download a csv file (retaining the filename).

最简单、最干净的方法是什么?

What is the easiest and cleanest way?

feign-form github 页面上的多部分解决方案很冗长,对我不起作用.

The multipart solution on the feign-form github page is verbose and isn't working for me.

感谢任何帮助.

推荐答案

Feign client:

Feign client:

import feign.Response;

@FeignClient(value = "some-service")
public interface Client{
   @RequestMapping(method = RequestMethod.GET, value ="/download")
   Response downloadFile();
}

Feign Client 的使用:

Usage of Feign Client:

final Response response = client.downloadFile();
final Response.Body body = response.body();
final InputStream inputStream = body.asInputStream();

您应该检查响应是否为 200,如果不是,则抛出异常.文件名应在标题中

You should check if response is 200, if not, throws exception. File name should be in headers

这篇关于Feign下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆