Warm tip: This article is reproduced from serverfault.com, please click

javascript-如何将文件或文件夹移动到Google Drive API中的另一个文件夹?

(javascript - How can i move the file or folder to another folder in google drive api?)

发布于 2020-12-03 14:17:08

我已按照文档(https://developers.google.com/drive/api/v3/folder#inserting_a_file_in_a_folder中的说明进行了所有操作但这对我不起作用。我已经更正了这个脚本:

window.gapi.client.drive.files.get({
        fileId: fileId,
        fields: 'parents'
      }).then(res => {
        console.log(res)
        window.gapi.client.drive.files.update({
          fileId: this.fileData.id,
          addParents: folderId,
          removeParents: res.result.parents[0],
          fields: 'id, parents'
        }).then(res => {
          console.log(res)
        })
      })

现在它将文件移动到其他位置,但不会删除当前位置。也就是说,在完成我的代码后,就像复制文件,而不是移动它。

Questioner
Mikhail
Viewed
0
ale13 2020-12-10 19:12:03

你正在使用的代码段仅删除第一个父级。

为了正确删除所有父母,你必须在代码中添加以下行:

var previousParents = res.result.parents.join(',');

并且在调用该update方法时,你将必须删除previousParents

removeParents: previousParents,

参考