Here is a quick example using CORS .
The file identifier is stored in the variable < theID >; this identifier is unique and will not change until the file is deleted (the trashed file is not deleted).
- First,
gapi.client.request retrieves the downloadUrl property; the return value is a short-range value; - Then
callback: function sends an authenticated request to get the contents of the file, thanks to its <downloadUrl>; - And the winner ... returns via
onreadystatechange = function( theProgressEvent ) .
.
gapi.client.request({ 'path': '/drive/v2/files/'+theID, 'method': 'GET', callback: function ( theResponseJS, theResponseTXT ) { var myToken = gapi.auth.getToken(); var myXHR = new XMLHttpRequest(); myXHR.open('GET', theResponseJS.downloadUrl, true ); myXHR.setRequestHeader('Authorization', 'Bearer ' + myToken.access_token ); myXHR.onreadystatechange = function( theProgressEvent ) { if (myXHR.readyState == 4) {
tested with "Chrome 20.0.1132.57 m" and "Firefox 14.0.1"
source share