在Google云端硬盘中找不到上传的文件

闪光灯12

我只是从Google驱动器开始,已经成功上传了文件并列出了所有文件,但是我似乎无法在Google驱动器中找到上传的文件?

fs.readFile('credentials.json', (err, content) => {
    if (err) return console.log('Error loading credentials', err);
    const credentials = JSON.parse(content);
    const { client_email, private_key } = credentials;

    auth = new google.auth.JWT(
      client_email,
      null,
      private_key,
      SCOPES,
    );
    drive = google.drive({
      version: 'v3',
      auth,
    });
  });

List of files from drive

drive.files.list({}, (err, res) => {
    if (err) throw err;
    const files = res.data.files;
    console.log(files);
    if (files.length) {
    files.map((file) => {
      console.log(file);
    });
    } else {
      console.log('No files found');
    }
  });

Upload file

const fileMetadata = {
    name: 'test_only', // file name that will be saved in google drive
  };

  const media = {
    mimeType: 'image/png',
    body: fs.createReadStream('image.png'), // Reading the file from our server
  };

    // Uploading Single image to drive
  drive.files.create(
    {
      resource: fileMetadata,
      media: media,
    },
    async (err, file) => {
      console.log(err);
      if (err) {
        // Handle error
        console.error(err);
      } else {
        console.log(file.data.id);
      }
    }
  );

文件列表中的结果

我错过了什么?

Tanaike

相信您目前的情况如下。

  • 从授权脚本中,发现您正在使用服务帐户。

      auth = new google.auth.JWT(
        client_email,
        null,
        private_key,
        SCOPES,
      );
    
  • 您可以使用脚本上载文件并检索文件列表。

修改要点:

  • I can't seem to find my uploaded files in my google drive,我认为您遇到问题的原因是使用服务帐户上传文件。在这种情况下,服务帐户的云端硬盘与您的Google云端硬盘不同。这样,上传的文件将无法显示在您的Google云端硬盘中。而且,服务驱动器帐户无法直接在浏览器中显示。

作为一种在浏览器中显示上载文件的解决方法,我想采用以下解决方法。

解决方法1:

在这种解决方法中,您的Google云端硬盘中的文件夹与服务帐户的电子邮件共享。并将上传的文件放入共享文件夹。这样,您可以使用Google云端硬盘中的服务帐户查看上传的文件。

解决方法2:

在这种解决方法中,服务帐户中的文件夹与您的Google帐户的电子邮件共享。并将上传的文件放入共享文件夹。这样,您可以使用浏览器中的服务帐户查看上载的文件。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将文件上传到Google云端硬盘中的特定文件夹

将文件上传到Google云端硬盘?

无法使用API在Google云端硬盘中打开上传的文件

Google云端硬盘API将文件上传到Java团队硬盘

C#Google云端硬盘APIv3上传文件

使用Google Apps脚本从Google云端硬盘中的多个上传元素上传本地文件

如何使用Google App脚本重命名由Google云端硬盘托管的de pdf文件(在对象错误中找不到函数setName)

使用gapi将文件上传到Google云端硬盘

Xamarin表单-如何在UWP中从Google云端硬盘上传,删除,下载文件

Google colab找不到目录(“我的云端硬盘”)

将文件从网络上传到Google云端硬盘

无法将文件上传到Google云端硬盘中的文件夹

如何使用Apps脚本将云端硬盘中的现有文件上传到云端硬盘

如何以编程方式在Android Studio中的Google云端硬盘上上传和下载任何文件

无法在js中的Google云端硬盘上上传图片

找不到使用REST API上传到Google云端硬盘的文件

使用http上传到Google云端硬盘文件夹

将内存中的文件下载并上传到Google云端硬盘

将文件从Blobstore上传到Google云端硬盘

Google云端硬盘可以上传文件,但无法查看

在后台将文件上传到Google云端硬盘

Python:如何使用folderId将文件上传到Google云端硬盘中的特定文件夹

Google云端硬盘文件:找不到项目或您无权访问它

Ruby:在Heroku中几个小时内突然找不到上传的文件

使用意图将文件上传到Google云端硬盘

使用Dropzone将文件上传到Google云端硬盘

使用php curl将文件上传到Google云端硬盘

Google云端硬盘文件上传已转换为文档

Google 云端硬盘上传文件