【问题标题】:Move file from Drive to TeamDrive folder appscript将文件从云端硬盘移动到团队云端硬盘文件夹应用脚本
【发布时间】:2019-04-18 17:11:49
【问题描述】:

我想使用来自 AppmMaker 的脚本将文件从 MyDrive 传输到 TeamDrive。我使用 DriveApp 在 MyDrive 中创建文件,并使用来自 appmaker 的 DrivePicker 小部件,我从目标文件夹获取 id 以保存文件。 DriveApp 可以在 TeamDrive 中移动文件

var file = DriveApp.getFileById(fileId);
var parentFolder = DriveApp.getFolderById(TEAM_DRIVE_ID);
parentFolder.addFile(file);

但不在 TeamDrive 的文件夹中。

我已尝试使用此代码:

function moveFileToFolder(fileIds, newFolderId) {  
  var file = Drive.Files.get(fileIds, {supportTeamDrives: true,supportsTeamDrives: true});

  Drive.Files.patch(file, fileIds, {
    removeParents: file.parents.map(function(f) { return f.id; }),
    addParents: [newFolderId],
    supportTeamDrives: true,
    supportsTeamDrives: true
  });
}

我遇到错误“无法在团队云端硬盘项目上设置共享限制”。

参考:How to move a file from MyDrive to Team Drive?

(引用的解决方案不起作用,因为我想将其移动到 teamdrive 的文件夹中,而不是直接在 teamdrive 中)

有什么想法吗?

【问题讨论】:

  • 尝试使用update 而不是patch,或者如果您需要继续使用patch,请明确删除云端硬盘文件中存在但团队云端硬盘文件中不存在的各种不适用的元数据属性.
  • 感谢您的回答。 update 返回相同的错误,我没有找到任何关于如何删除这些元数据的文档。
  • 您可以显式控制文件元数据,因此获取现有元数据,从返回的对象中删除不适用的属性,然后将其作为移动文件的新元数据提供。

标签: google-apps-script google-app-maker google-drive-shared-drive


【解决方案1】:

文件元数据中有一个参数需要更改,因为云端硬盘文件和团队云端硬盘文件不同。你可以改变它

var file = Drive.Files.get(FileId);
file.capabilities.canMoveTeamDriveItem = true;

然后简单地移动它

var fileDriveApp = DriveApp.getFileById(FileId); 
fileDriveApp.getParents().next().removeFile(fileDriveApp);
var folder = DriveApp.getFolderById(foldersId);
folder.addFile(fileDriveApp);

参考:https://developers.google.com/drive/api/v3/reference/files

【讨论】:

  • 您的问题与移动文件有关,提供的答案是创建新文件。请适当编辑您的问题/答案,以免其他人感到困惑。
猜你喜欢
  • 2020-02-21
  • 2018-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-21
  • 2018-06-21
  • 2019-02-26
  • 2018-09-06
相关资源
最近更新 更多