如何在Google脚本中修复“ Blob对象对此操作必须具有非空数据。(第6行,文件“代码”)”

时间:2019-07-26 00:04:14

标签: google-apps-script

我想创建一个重复文件,然后通过电子邮件发送,但出现错误:

  

Blob对象必须具有非空数据才能执行此操作。 (第6行,文件“代码”)

我尝试更改:

var duplicatedFileId = sourceFile.makeCopy(sourceFile+" copy", sourceFolder).getId(); 

进入:

var duplicatedFileId = sourceFile.makeCopy(sourceFile+" copy", sourceFolder).getId().toString();

但是我又遇到了一个错误。

function myFunction() {
  var sourceFolder = DriveApp.getFolderById("1DiqneJbyPN90SvE7uGaesdrd7Po6NJLl");
  var sourceFile = DriveApp.getFileById("1qAabbU8MlWmV8J1rdI5A8eEvUPLXAqKnz6fp1vxUOzQ");
  var duplicatedFileId = sourceFile.makeCopy(sourceFile+" copy", sourceFolder).getId();
  var duplicatedFile = DriveApp.getFileById(duplicatedFileId);
  GmailApp.sendEmail("someone@gmail.com", "Testing attaching a file", "This is a test email", {
    attachments:[duplicatedFile.getAs(MimeType.GOOGLE_DOCS)],
    name:sourceFile+" copy"
  });
}

我希望发送重复的文件,但出现错误:

  

Blob对象必须具有非空数据才能执行此操作。 (第6行,文件“代码”)。

1 个答案:

答案 0 :(得分:1)

尝试一下:

function runTwo() {
  var sourceFolder=DriveApp.getFolderById("1DiqneJbyPN90SvE7uGaesdrd7Po6NJLl");
  var sourceFile=DriveApp.getFileById("1qAabbU8MlWmV8J1rdI5A8eEvUPLXAqKnz6fp1vxUOzQ");
  var duplicatedFileId = sourceFile.makeCopy(sourceFile.getName() + "_copy", sourceFolder).getId();
  var duplicatedFile = DriveApp.getFileById(duplicatedFileId);
  GmailApp.sendEmail("someone@gmail.com", "Testing attaching a file", "This is a test email", {attachments:[duplicatedFile]});
}

将此行var duplicatedFileId = sourceFile.makeCopy(sourceFile+" copy", sourceFolder).getId();更改为此行var duplicatedFileId = sourceFile.makeCopy(sourceFile.getName() + "_copy", sourceFolder).getId();

此行GmailApp.sendEmail("someone@gmail.com", "Testing attaching a file", "This is a test email", { attachments:[duplicatedFile.getAs(MimeType.GOOGLE_DOCS)], name:sourceFile+" copy" });至此行GmailApp.sendEmail("someone@gmail.com", "Testing attaching a file", "This is a test email", {attachments:[duplicatedFile]});