How to move a file from MyDrive to Team Drive?

笑着哭i 提交于 2020-01-17 02:13:16

问题


I would like to use Google Apps Script to transfer a file from MyDrive to Team Drive. I can do this manually (so I know I have permission) and I enabled the Drive API (so was able to save to MyDrive). However, when I do this (which I got from another post):

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

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

I get this error:

Sharing restrictions cannot be set on a Team Drive item.

Any ideas?


回答1:


It appears I was overthinking it as the following works:

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


来源:https://stackoverflow.com/questions/53302468/how-to-move-a-file-from-mydrive-to-team-drive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!