简体   繁体   English

无法使用 googleapis 从 Google Drive 下载文件

[英]Not able to download the file from Google Drive using googleapis

So I'm trying to download the file from google drive using googleapis V3 but its showing me error of Property 'on' does not exist on type 'GaxiosPromise<Schema$File>'.所以我正在尝试使用 googleapis V3 从谷歌驱动器下载文件,但它向我显示“GaxiosPromise<Schema$File>”类型上不存在属性“on”的错误。

Here's my Code这是我的代码

var fileId ='FILE_ID'
const drive = google.drive({ version: 'v3', auth });
drive.files.get({
   fileId: fileId,
   alt: 'media'
})
.on('end', function () {    // error here
   console.log('Done');
})
.on('error', function (err) {
  console.log('Error during download', err);
})
.pipe(fs.createWriteStream(`./static/upload/${fileName}`));

follow this code here https://developers.google.com/drive/api/v3/manage-downloads在此处按照此代码https://developers.google.com/drive/api/v3/manage-downloads

I had a similar issue, I think there's another issue around for it somewhere but as far as I can remember you need to use the response object to pipe the writestream,ie我有一个类似的问题,我认为在某个地方还有另一个问题,但据我所知,您需要使用响应 object 到 pipe 写入流,即

drive.files.get({fileId: fileId, alt: 'media'}, {responseType: "stream"}, (err, res) => {
  if (err) {
    //   handle error
  } else {
    res.data
      .on("end", function () {
        console.log("Done");
      })
      .on("error", function (err) {
        console.log("Error during download", err);
      })
      .pipe(fs.createWriteStream(`./static/upload/${fileName}`));
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM