I am trying to get a download progress % for a huge file stored in my Google Drive unit when downloading from my Nodejs script.
So far I have written the code to download, which is working, however the on('data'....)
part is never called.
const downloadFile = (file) => {
const fileId = file.id;
const fileName = path.join(basePathForStorage, file.name);
const drive = google.drive({ version: 'v3', authorization });
let progress = 0;
return new Promise((resolve, reject) => {
drive.files.get(
{
auth: authorization,
fileId: fileId,
alt: 'media'
},
{ responseType: "arraybuffer" },
function (err, { data }) {
fs.writeFile(fileName, Buffer.from(data), err => {
// THIS PART DOES NOTHING
data.on('data',(d)=>{
progress += d.length;
console.log(`Progress: ${progress}`)
})
// --------------------
if (err) {
console.log(err);
return reject(err);
}
return resolve(fileName)
});
}
);
});
}
Looks like I can't find the way to show the progess of the download by calling on('data'....)
...wondering now if this is the correct way to do this, or if this is even possible.
I tried putting the on('data'....)
code as it is now inside the writeFile
function but also inside the callback from drive.files.get
and nothing works.