Download video from Url with Retrofit

I use Retrofit to use web services, and so far this is great. But does Retrofit do a way to download videos from URLs?

I checked this link, but the @Streaming annotation @Streaming no longer available. Upload image with retro upload

+8
android retrofit video-streaming download
source share
2 answers

Yes, you can use the @Streaming annotation available from version 1.6.0. Make sure you are using this version.

As pointed out in changelog : New: @Streaming on the Response will skip body buffering to byte [] before delivery.

 interface Api { @Get("path/to/your/resource") @Streaming Response getData(); } 

Then you should be able to directly pass from InputStream

 Response response = api.getData() InputStream is = response.getBody().in(); // stream your data directly from the InputStream! 

Keep in mind that my example is synchronous for simplicity.

+15
source share

To end @Miguel Lavigne, answer here how to do it with Retrofit 2:

 interface Service { @GET("path/to/your/resource") @Streaming Call<ResponseBody> getData(); } Call<ResponseBody> call = service.getData(); try { InputStream is = call.execute().body().byteStream(); (...) } catch (IOException e) {...} 
+2
source share

All Articles