question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Help] Google Drive export example not working

See original GitHub issue

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;
            });
    });
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

50reactions
SergioDonaticommented, Feb 22, 2018

finally i made a export script working for me, i hope help someone else;

function download(fileId, name, done) {
        const dest = fs.createWriteStream(name + '.csv');
        drive.files.export({
            fileId: fileId,
            mimeType: 'text/csv'
        }, {
            responseType: 'stream'
        },function(err, response){
            if(err)return done(err);
            
            response.data.on('error', err => {
                done(err);
            }).on('end', ()=>{
                done();
            })
            .pipe(dest);
       });
}

is important the responseType: "stream" to have a stream in response.data. options are passed to axios.request, here you can find all options

7reactions
krissetto-oldcommented, Feb 7, 2018

I’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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot problems running or exporting a report
Technical issues are usually the reason a report fails to run or export. For example, reports containing very long date ranges may timeout...
Read more >
How to fix Google Drive not downloading files - Setapp
As you can see, the Google Drive not downloading problem has lots of potential solutions. First, try a few options of downloading the...
Read more >
7 Tips to Fix Google Drive Not Loading Problem
Method 1. Clear the Caches and Cookies · Method 2. Check for Update · Method 3. Disable Browser's Plugins · Method 4. Restart...
Read more >
Files: export | Google Drive
Exports a Google Workspace document to the requested MIME type and returns ... If not specified, the response includes a default set of...
Read more >
Best Fix: Google Drive Not Downloading - Alphr
If you're trying to download a document, photo, or video to your Android device from Drive and it's not working, there could be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found