【问题标题】:Using Google drive API to upload files in G-Drive facing issue使用 Google drive API 在 G-Drive 中上传文件面临问题
【发布时间】:2021-01-25 04:09:39
【问题描述】:

*嗨, 使用 Google Drive API 上传 Drive 中的文件。 该文件已成功上传,但作为响应,文件 ID 显示为未定义。 我必须使用文件 ID 来获取更多代码 *

function uplodeFile(auth){
    const drive = google.drive({version: 'v3', auth});
    var fileMetadata = {
        'name': 'error.jpg'
      };
      var media = {
        mimeType: 'image/jpeg',
        body: fs.createReadStream('Capture.JPG')
      };
      drive.files.create({
        resource: fileMetadata,
        media: media,
        fields: 'id'
      }, function (err, file) {
        if (err) {
          // Handle error
          console.error(err);
        } else {
          console.log('File Id: ', file.id);
        }
      });
}

This is the Snippet of the response

【问题讨论】:

  • 我认为这个问题可能是重复的。但我找不到重复的问题。所以我回答了。

标签: node.js api google-drive-api drive


【解决方案1】:

如果你使用的是最新版的Node.js的googleapis,那么下面的修改呢?

发件人:

console.log('File Id: ', file.id);

收件人:

console.log('File Id: ', file.data.id);
  • 当前阶段,最新版本为v61.0.0

参考:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-07
    • 1970-01-01
    • 1970-01-01
    • 2020-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多