function downloadFile(auth){ const drive = google.drive({ version: 'v3', auth }); // drive.files.get({ fileId: fileId, fields: '*' }, (err, res) => { // if (err) return console.log('The API returned an error: ' + err); // console.log(res.data); // }); var fileId = '1RDrrFGV2fM7jvnxGFileId'; var dest = fs.createWriteStream('./samples');
drive.files.get({fileId: fileId, alt: 'media'}, {responseType: 'stream'}, function(err, res){ res.data .on('end', () => { console.log('Done'); }) .on('error', err => { console.log('Error', err); }) .pipe(dest); } );}
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'data' of undefined at /home/sshinde/workspace/node-sample-apps-script/index.js:157:13 at process._tickCallback (internal/process/next_tick.js:68:7)(node:546) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)(node:546) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
drive.files.get(
{fileId: fileId, alt: 'media',},
{responseType: 'stream'}, (err, { data }) => {
if (err) {
returnData.push(["ERR"]);
returnData.push("" + err);
} else {
data.pipe(file);
returnData.push("Downloaded");
}
callback(returnData);
});
![]() |
Yasir Karam
about.me/karamyasir
|
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/cae0a029-899f-40d1-b130-99e2b21e1083%40googlegroups.com.
{responseType: 'stream'}, (err, { data }) => {
(node:7580) UnhandledPromiseRejectionWarning: TypeError: Cannot destructure property `data` of 'undefined' or 'null'.
drive.files.get( {fileId: fileId, alt: 'media',}, {responseType: 'stream'}, (err, { data }) => { if (err) { returnData.push(["ERR"]); returnData.push("" + err); } else { data.pipe(file); returnData.push("Downloaded"); } callback(returnData); });
![]()
Yasir Karamabout.me/karamyasir
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.
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
![]() |
Yasir Karam
about.me/karamyasir
|
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/cae0a029-899f-40d1-b130-99e2b21e1083%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/1ec2fcfa-4e87-4fa9-a775-a69fcaa3809d%40googlegroups.com.