如何在 google drive api 中复制文件夹?

米哈伊尔

该文档描述了如何复制一个文件 ( https://developers.google.com/drive/api/v2/reference/files/copy ),但没有提及该文件夹。此脚本在复制文件夹时会出现错误 403:

window.gapi.client.drive.files
          .create({
            resource: {
              name: this.currentFile.newTitle,
              mimeType: 'application/vnd.google-apps.folder'
            },
            fields: 'id, name, mimeType, createdTime'
          }).then(res => {
            window.gapi.client.drive.files.list({
              q: `'${this.currentFile.id}' in parents and trashed = false`,
              fields: 'files(id, name, createdTime, mimeType)'
            }).then(res => {
              console.log(res)
              res.result.files.forEach(file => {
                window.gapi.client.drive.files
                  .copy({
                    fileId: file.id,
                    fields: 'id, name, mimeType, createdTime'
                  }).then(res => console.log(res))
              })
            })
          })

我尝试了在 Internet 上找到的其他解决方案,但它们也不起作用。您能否附上一些适合您的示例代码?

达姆托

files.copy 只是复制单个文件

在此处输入图片说明

如果您检查链接的文档页面的最顶部,您会注意到它声明它不适用于文件夹。

要复制文件夹,您应该首先执行 file.create 并创建一个文件夹,然后执行 file.list 循环遍历文件夹中的所有文件,然后对每个文件执行 file.copy。

文件夹方法中没有批量复制所有内容。你将不得不一项一项地做这件事。

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

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

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Google Drive API中按路径查找文件夹ID?

如何在Google Drive Android API中获取已创建文件夹的DriveId

如何在Google Drive API中禁用文件夹的递归(Swift 5)

如何使用Google的Python Drive Client API在Team Drive中创建文件夹?

如何在Google Drive API v3 PHP中的特定文件夹中列出文件

在Google Drive API中搜索文件或文件夹时如何获得面包屑?

如何不检测在 google drive changes api 中打开文件和文件夹

如何在Google Drive API上按文件夹获取文件列表

使用Google Drive API上传文件夹中的文件

如何使用Google API在Team Drive中创建文件夹?

如何使用 Google Drive API Javascript 列出特定文件夹中的更改

如何在Flutter应用中使用Google Drive API创建文件夹?

通过 API 重命名 Google Drive 中的文件夹

Google Drive API搜索文件夹

如果文件夹中不存在文件,则删除文件夹 - Google Drive API

如何将Google文档复制到Google Drive Service中的另一个文件夹

它如何在 Google Picker 中为 Google Drive 文件显示指定文件夹?

如何列出 Google Drive 根文件夹中的文件和文件夹

如何在Google Drive REST API中查看文件的权限?

如何在根目录中创建文件夹并在Android的Google Drive REST API v3中获取其ID

如何使用 Google Drive API v3 将可恢复上传到 Python 中的共享文件夹?

如何在Google Plus照片/ Picasa中重新索引或删除旧的Google Drive文件夹

如何使用Google Drive API和Python将文件上传到特定文件夹?

使用 pydrive 或 google drive api 在 google drive 中复制文件

Google Api/Python:上传新文件之前 Google Drive 中的空文件夹

Google Drive API:如何从Google Drive下载文件?

如何在 PHP 中获取与 Google Drive Api 的共享链接

Google Drive Java Api-文件夹中的更新文件。

使用 Google Drive Java API 返回文件夹中的所有文件