我已按照文档(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)
})
})
现在它将文件移动到其他位置,但不会删除当前位置。也就是说,在完成我的代码后,就像复制文件,而不是移动它。
你正在使用的代码段仅删除第一个父级。
为了正确删除所有父母,你必须在代码中添加以下行:
var previousParents = res.result.parents.join(',');
并且在调用该update
方法时,你将必须删除previousParents
:
removeParents: previousParents,