I'm trying to integrate the Google Drive in my angular application So that our users can copy the content from docs and download their images to my application. As per the file:get API Documentation, I'm using the below code to get the file
var request = gapi.client.drive.files.get({
'fileId': fileId
});
var temp = this;
request.execute(function (resp) {
});
But in the response I'm getting only File name and ID.There is no download URL which is required for downloadFile function. Response:
{kind: "drive#file",
id: "1KxxxxxxxxxxxxxxycMcfp8YWH2I",
name: " Report-November",
mimeType: "application/vnd.google-apps.spreadsheet",
result:{
kind: "drive#file"
id: "1K7DxawpFz_xiEpxxxxxxxblfp8YWH2I"
name: " Report-November"
mimeType: "application/vnd.google-apps.spreadsheet"
}
}
Download File Function:
/**
* Download a file's content.
*
* @param {File} file Drive File instance.
* @param {Function} callback Function to call when the request is complete.
*/
downloadFile(file, callback) {
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 () {
callback(xhr.responseText);
};
xhr.onerror = function () {
callback(null);
};
xhr.send();
} else {
callback(null);
}
}
Am I missing anything? Is it the right approach to download a file from Drive in the client side?