Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feign for downloading file

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?

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

Any help is appreciated.

like image 730
user12722869 Avatar asked Nov 16 '25 07:11

user12722869


1 Answers

Feign client:

import feign.Response;

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

Usage of Feign Client:

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

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

like image 166
kev Avatar answered Nov 19 '25 08:11

kev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!