google-api-nodejs-client: [Help] Google Drive export example not working
I have the code from the drive export example with the sampleClient and it’s producing an error.
(node:3593) UnhandledPromiseRejectionWarning: TypeError: Cannot read property ‘on’ of undefined
function download(fileId) {
drive.files.get({
fileId: fileId
}, (err, metadata) => {
if (err) {
throw err;
}
console.log('Downloading %s...', metadata.name);
const dest = fs.createWriteStream(metadata.name + '.csv');
drive.files.export({
fileId: fileId,
mimeType: 'text/csv'
})
.on('error', err => {
console.error('Error downloading file!');
throw err;
})
.pipe(dest);
dest
.on('finish', () => {
console.log('Downloaded %s!', metadata.name);
process.exit();
})
.on('error', err => {
console.error('Error writing file!');
throw err;
});
});
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 20 (3 by maintainers)
finally i made a export script working for me, i hope help someone else;
is important the
responseType: "stream"
to have a stream inresponse.data
. options are passed toaxios.request
, here you can find all optionsI’m having the same issue running the sample code from the drive download example. (https://github.com/google/google-api-nodejs-client/blob/master/samples/drive/download.js)
TypeError: Cannot read property ‘on’ of undefined
If you prefer async/await… this worked for me:
The docs here are still out of date: https://developers.google.com/drive/api/v3/manage-downloads#node.js
Just wanted to let someone know the official documentation still isn’t updated. It’s very frustrating when the examples don’t work and pretty much nulls the value of any documentation when you have to debug a library just to download a file. 😦
FYI, example to export(…) without using a stream , to pdf for example:
Here is one if the docs pages that need the fix in their examples https://developers.google.com/drive/api/v3/manage-downloads
This must have broke when axios was added.
I see it now in the axios documentation: