Google Drive using JavaScript: handling file contents

Two months ago in Google Drive Authorization using JavaScript , @Nivco wrote about " Processing file contents ", very tantalizing:

We could also improve the file content server to support XHR requests.

So, where can we find news or roadmaps, information and related information about this feature?



Actually, this question is the answer ... (to another question )

+2
source share
2 answers

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) { // 1=connection ok, 2=Request received, 3=running, 4=terminated if ( myXHR.status == 200 ) { // 200=OK console.log( myXHR.response ); } } } myXHR.send(); } }); 

tested with "Chrome 20.0.1132.57 m" and "Firefox 14.0.1"

+3
source

The file download endpoint now supports CORS requests. Yesterday I updated the response text for Google Drive Authorization using JavaScript to make sure it reflects the latest state of the API. I just deleted this final comment you are referring to :)

+2
source

All Articles