Google Drive using JavaScript: Handling file content - Stack Overflow

Two months ago, in Authorization of Google Drive using JavaScript,@Nivco was writing about "Handli

Two months ago, in Authorization of Google Drive using JavaScript,
@Nivco was writing about "Handling file content", a very tantalizing:

We could also improve the file content server so that it supports XHR requests.

So, where could "we" find news or roadmaps, information et coetera about this feature?



Actually, this question is a reply... (to another question)

Two months ago, in Authorization of Google Drive using JavaScript,
@Nivco was writing about "Handling file content", a very tantalizing:

We could also improve the file content server so that it supports XHR requests.

So, where could "we" find news or roadmaps, information et coetera about this feature?



Actually, this question is a reply... (to another question)

Share Improve this question edited May 23, 2017 at 11:48 CommunityBot 11 silver badge asked Jul 20, 2012 at 11:33 PierrePierre 2633 silver badges14 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Here is a short example using CORS.
The ID of the file is stored in variable <theID> ; this ID is unique and won't change as long as the file is not deleted (a trashed file is not deleted).

  • First gapi.client.request retrieves the downloadUrl property ; the returned value is a short lived value ;
  • Then, the callback: function sends an authenticated request in order to retrieve the contents of the file, thanks to its <downloadUrl> ;
  • And the winner is… returned 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"

The file download endpoint now supports CORS requests. I have updated the body of the answer to Authorization of Google Drive using JavaScript yesterday actually to make sure it reflects the latest state of the API. I just removed that trailing ment you are referring to :)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745254374a4618867.html

相关推荐

  • Google Drive using JavaScript: Handling file content - Stack Overflow

    Two months ago, in Authorization of Google Drive using JavaScript,@Nivco was writing about "Handli

    2小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信