javascript - 如何将文件或文件夹移动到 google drive api 中的另一个文件夹?
问题描述
我按照文档(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,
参考
推荐阅读
- python - EMR 笔记本不存在 IAM 角色
- angular - 使用 const { } 时哪些属性会暴露在外部
- python - 无法使用 python 3.8 安装 cvxpy
- laravel - 如何在 Laravel/Lighthouse/Passport/Nuxt 应用程序上使用 Dusk 测试登录?
- git - 如何可靠地确定远程存储库中的最后提交日期?
- javascript - 无法在 vue 图像 src 绑定中使用波浪号 (~)
- android - 添加 ClickListener 时出现 NullPointerException
- assembly - 如何在 ARM Assembly 中将大写字母转换为小写字母?
- php - 使用 php 将联系人保存到手机不直接打开保存联系人屏幕(iPhone 用户)
- swift - 以编程方式滚动到 WKWebView 的底部不起作用