2017-04-09 63 views
0

我发送一个谷歌文档作为附件在一个电子邮件工作正常,但附件被称为'export.docx',我不知道如何改变它。我正在使用这个API - https://developers.google.com/drive/v2/reference/files/export更改文档的名称使用谷歌脚本文件导出

我的代码如下。如果有人可以帮助我改变附件的名字,那就太棒了!谢谢!

function run(id, callback) { 
    var service = getDriveService(); 
    if (service.hasAccess()) { 
    var token = service.getAccessToken(); 
    var response = UrlFetchApp.fetch('https://www.googleapis.com/drive/v2/files/' + id + '/export?mimeType=application/vnd.openxmlformats-officedocument.wordprocessingml.document', { 
     headers: { 
     Authorization: 'Bearer ' + token 
     } 
    }); 
    MailApp.sendEmail({ 
     to: email, 
     subject: "Attachments", 
     htmlBody: "Please see attached.", 
     attachments: [response] 
    }); 
    } else { 
    Logger.log("Access denied") 
    } 
} 

回答

1

这样做可以重命名的名称,像这样:

function run(id, callback) { 
    var service = getDriveService(); 
    if (service.hasAccess()) { 
    var token = service.getAccessToken(); 
    var response = UrlFetchApp.fetch('https://www.googleapis.com/drive/v2/files/' + id + '/export?mimeType=application/vnd.openxmlformats-officedocument.wordprocessingml.document', { 
     headers: { 
     Authorization: 'Bearer ' + token 
     } 
    }); 
    MailApp.sendEmail({ 
     to: email, 
     subject: "Attachments", 
     htmlBody: "Please see attached.", 
     attachments: [response.getBlob().setName("NewName")] 
    }); 
    } else { 
    Logger.log("Access denied") 
    } 
} 

基本上,转换成BLOB和使用setnewName响应,使用的setName功能

希望帮助