Last active
February 25, 2022 15:57
-
-
Save pizzapanther/8241364 to your computer and use it in GitHub Desktop.
Download A Google Drive File via Javascript
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
function downloadGDriveFile (file) { | |
if (file.downloadUrl) { | |
var accessToken = gapi.auth.getToken().access_token; | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', file.downloadUrl); | |
xhr.setRequestHeader('Authorization', 'Bearer ' + accessToken); | |
xhr.onload = function() { | |
var content = xhr.responseText; | |
do_something_with_file_content(file.title, content); | |
}; | |
xhr.onerror = function() { | |
alert("Download failure."); | |
}; | |
xhr.send(); | |
} | |
else { | |
alert("Unable to download file."); | |
} | |
} | |
var request = gapi.client.drive.files.get({'fileId': fid}); | |
request.execute(downloadGDriveFile); |
What is the "file" in function downloadGDriveFile (file) ???
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uncaught ReferenceError: gapi is not defined