【发布时间】:2018-09-11 04:36:55
【问题描述】:
我需要使用 Drive.Files.copy 函数来复制团队云端硬盘中的文件。功能是将模板 Google Doc 复制到新文件和文件夹。
下面的函数似乎是复制文件,但生成的文件是 PDF(原始文件是 Google Doc)。这可能是一些我没有看到的简单的东西。
teacherFolder 是目的地。
learnerDoc 是原始文件。
newDocc 是新文件。
function test() {
var newFile = {
title: "Learner Guide - test",
description: "New student learner guide",
mimetype: 'application/vnd.google-apps.file',
supportsTeamDrives: true,
kind: "drive#user",
includeTeamDriveItems: true
};
// find Teacher's Learner Guides folder
var teacherFolder = DriveApp.getFolderById('1qQJhDMlHZixBO9KZkkoSNYdMuqg0vBPU');
// create duplicate Learner Guide Template document
var learnerDoc = DriveApp.getFileById('1g6cjUn1BWVqRAIhrOyXXsTwTmPZ4QW6qGhUAeTHJSUs');
//var newDocc = Drive.Files.copy(newFile, learnerDoc.getId());
var newDocc = Drive.Files.insert(newFile, learnerDoc.getBlob(), newFile);
var DriveAppFile = DriveApp.getFileById(newDocc.id);
teacherFolder.addFile(DriveAppFile);
Logger.log('file = ' + newDocc.fileExtension);
}
如何在团队云端硬盘中创建重复的 Google 文档并将其移至其他文件夹?
【问题讨论】:
-
虽然我不确定我是否能正确理解您的情况,但您的脚本中似乎没有使用
Drive.Files.copy()。如果这不是您的最新脚本,您可以更新它吗?然后,在 Google Docs 的情况下,当getBlob()检索文件的 blob 时,blob 的 mimeType 变为application/pdf。我认为这是 Google 的规范。 -
当我取消注释 Drive.Files.copy() 行时,会抛出错误,“找不到文件:1g6cjUn1BWVqRAIhrOyXXsTwTmPZ4QW6qGhUAeTHJSUs”,所以我尝试插入文件。
-
@Tanaike 副本正在运行。父母不是。文件不在父母的文件夹 ID 中。 var newFile = { "title": "Learner Guide - test", "description": "New student learning guide", "parents": [teacherFolder.getId()], "supportsTeamDrives": true, "kind": "drive #file", "includeTeamDriveItems": true }; var learnerDoc = DriveApp.getFileById('1g6cjUn1BWVqRAIhrOyXXsTwTmPZ4QW6qGhUAeTHJSUs'); var newDocc = Drive.Files.copy(newFile, learnerDoc.getId(), newFile);
-
感谢您的回复。虽然我发布了一个显示修改点的答案,但我注意到您刚才发布为an another question。所以我删除了我的答案。如果您添加问题的更多信息,请使用编辑按钮将它们添加到您的问题中。因为您发布的答案没有解决您的问题。通过更新您的问题,其他有相同问题的用户可以看到您的问题。
标签: google-apps-script google-drive-api google-drive-shared-drive