How to use Google Drive API to download files with Javascript

前端 未结 4 902
耶瑟儿~
耶瑟儿~ 2020-12-30 11:38

I want to download files from google drive with javascript API. I have managed to authenticate and load list of files using gapi.client.drive.files request. How

4条回答
  •  孤城傲影
    2020-12-30 12:17

    I found out that I can actually retrieve URLs of all those files from the folder using files'
    webViewLink or webViewContent attributes. A file which is of Google Drive type (Google Doc, Google Sheet, etc...) will have webViewLink attribute and a non Google Drive type file will have webContentLink. The webViewLink will open the file in Google Drive and the webContentLink will download the file. My code:

    var request = gapi.client.drive.files.list({
        q:"'0Bz9_vPIAWUcSWWo0UHptQ005cnM' in parents", //folder ID
        fields: "files(id, name, webContentLink, webViewLink)"
    });
    request.execute(function(resp) {
        console.log(resp); //access to files in this variable
    }
    

提交回复
热议问题