0

I try to allow users to select images from the users google drive. I follow this doc: https://developers.google.com/picker/docs/. When i recive the image url from google ('/drive/v2/files/' + FileId) then i try to download tile image in my .NET code:

var WebRequest = (HttpWebRequest)System.Net.WebRequest.Create(url);
WebRequest.AllowWriteStreamBuffering = true;
WebRequest.Timeout = 30000;
WebRequest.KeepAlive = false;
WebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";
WebRequest.AllowAutoRedirect = true;
WebRequest.Headers.Add("Authorization", "Bearer " + token);                 

byte[] Arr;
using (var WebResponse = WebRequest.GetResponse())
{
     using (var Stream = WebResponse.GetResponseStream())
     {
          Arr = Stream.StreamToByteArray();
     }

     WebResponse.Close();
}
return Arr;

But all i get is a empty (white) webpage. With the url i get from google, i can se the image in my browser, but i cant download it in my code.

How can i get the image downloaded?

1 Answer 1

0

Use instead WebClient:

client = new WebClient();
client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
client.Headers.Add("Authorization", "Bearer " + token); 
client.AllowWriteStreamBuffering = true;
return client.DownloadData(url); /// DownloadData returns a byte array
Sign up to request clarification or add additional context in comments.

1 Comment

Same problem, i get a empty page when i try to download the image from google drive. I can download "public" images from example facebook but not from google drive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.