Created
October 6, 2016 18:20
-
-
Save gazlu/1eded0c78d7bf0057cb609da752cb990 to your computer and use it in GitHub Desktop.
Download Image or file with RestSharp (Rest Sharp)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
It works.. you save my life. hehe thanks.. :)
For some reason this doesn't work for zip files. The file is downloaded, but it is corrupted.
@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.
Thank you for this, works great to pull user photos out of Microsoft Graph API
Also worked for me :) Thanks!
what is directory?
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
Nice! Thank you for sharing. This tip made my day.
@GrandaNet