Skip to content

Instantly share code, notes, and snippets.

@gazlu
Created October 6, 2016 18:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gazlu/1eded0c78d7bf0057cb609da752cb990 to your computer and use it in GitHub Desktop.
Save gazlu/1eded0c78d7bf0057cb609da752cb990 to your computer and use it in GitHub Desktop.
Download Image or file with RestSharp (Rest Sharp)
RestClient restClient = new RestClient(@"http://ia.media-imdb.com/images/M/MV5BMjM5OTQ1MTY5Nl5BMl5BanBnXkFtZTgwMjM3NzMxODE@._V1_SX300.jpg");
var fileBytes = restClient.DownloadData(new RestRequest("#", Method.GET));
File.WriteAllBytes(Path.Combine(directory, "poster-got.jpg"), fileBytes);
@GrandaNet
Copy link

GrandaNet commented Sep 4, 2017

Nice! Thank you for sharing. This tip made my day.

@GrandaNet

@jerviechronix
Copy link

It works.. you save my life. hehe thanks.. :)

@AvaSpa
Copy link

AvaSpa commented Jul 12, 2019

For some reason this doesn't work for zip files. The file is downloaded, but it is corrupted.

@juniorschroder
Copy link

@AvaSpa you need to add header Accpet with value application/zip
The zip file is not corrupted, if you are saving in a file .zip, rename it to .html and you will see the exception or error details. In my case header accept: application/zip solve the problem.

@MorningZ
Copy link

Thank you for this, works great to pull user photos out of Microsoft Graph API

@nadvolod
Copy link

nadvolod commented Feb 19, 2021

Also worked for me :) Thanks!

@acordobaj
Copy link

what is directory?

@MorningZ
Copy link

what is directory?

The string value of the directory to store file in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment