C# Here if it matters. What I am trying to do is allow users on mobile phones (or desktops) to upload files to my web server. I have the picker built, got the auth all figured out for the scope drive.readonly.
But what I keep seeing in the examples when it comes time to download the file is they download it using Javascript and then upload it again to the server. I would like to get it from my server. I have this working fine with Dropbox, but google is a problem.
I followed the guide here: https://developers.google.com/picker/docs/
But then I send the fileId and token to the server:
function pickerCallback(data) {
if (data.action == google.picker.Action.PICKED) {
var datastring = "url=" + data.docs[0].url + "&name=" + data.docs[0].name + "&mimetype=" + data.docs[0].mimetype + "&fileId=" + data.docs[0].id + "&token=" + oauthToken;
$.ajax({
type: "POST",
url: "/FileUpload/GetGoogleDriveFile/",
data: datastring,
dataType: "json",
success: function (data) {
if (data.success != null && data.success == true) {
window.location.href = "@Html.Raw(AfterUploadDestination)";
}
else
{
alert("Error: " + data.ErrorMsg);
}
},
error: function (xhr, textStatus, errorThrown) {
console.log(xhr.responseText);
}
});
googlepicker.setVisible(false);
}
}
And then on the server I have something like...
var client = new System.Net.WebClient();
client.Headers.Set(HttpRequestHeader.Authorization, "Bearer " + file.token);
then something to consume the file:
doc.Contents = client.DownloadData(string.Format("https://www.googleapis.com/drive/v3/files/{0}?alt=media", file.fileId));
The problem is that the file is not just the binary stream of the file but the webpage itself that google displays when you go to the site with that link.
How in the world do I just download the file?
Thanks in advance and I hope this wasn't so long that no one reads it.