接收云端硬盘中的文件并发送确认电子邮件

时间:2015-10-07 20:42:20

标签: email google-apps-script drive

我想创建一个允许任何人将多个文件上传到我的投递箱的表单。但我也希望上传文件的人收到确认电子邮件。以下代码上传文件但发送电子邮件。请帮忙!

这是.gs

function doGet(e) {return HtmlService.createHtmlOutputFromFile('form.html');} 
function sendEmails(form) {

var message= ", your abstract was submitted. Send other work by APR 20";
var subject = "Application Received";
MailApp.sendEmail(form.myEmail, subject, message);
 }

function uploadFiles(form) {

try {

var dropbox = "New Abstracts";
var folder, folders = DriveApp.getFoldersByName(dropbox);

if (folders.hasNext()) {
  folder = folders.next();
} else {
  folder = DriveApp.createFolder(dropbox);
}


var blob = form.myFile1;    
var file = folder.createFile(blob);   
file.setDescription("Uploaded by " + form.myName);

var blob = form.myFile2;    
var file = folder.createFile(blob);   
file.setDescription("Uploaded by " + form.myName);

return "File uploaded successfully " + file.getUrl();

} catch (error) {

return error.toString();
  }
}

这是.html部分

<form id="myForm">
<input type="text" name="myName" placeholder="Your name..">
<input type="email" name="myEmail" placeholder ="Your email..">
<input type="file" name="myFile1" >
<input type="file" name="myFile2" >
<input type="submit" value="Upload File" 
       onclick="this.value='Uploading..';
                google.script.run.withSuccessHandler(fileUploaded)
                .uploadFiles(this.parentNode).sendEmails(this.parentNode);
                return false;">

<script>
function fileUploaded(status) {
    document.getElementById('myForm').style.display = 'none';
    document.getElementById('output').innerHTML = status;
}
</script>

<style>
 input { display:block; margin: 20px; }
</style>

我根据以下代码尝试此操作: http://www.labnol.org/internet/receive-files-in-google-drive/19697/

1 个答案:

答案 0 :(得分:1)

你不能像这样附加多次调用脚本:

google.script.run.withSuccessHandler(fileUploaded)
                .uploadFiles(this.parentNode).sendEmails(this.parentNode);

只执行uploadFiles(被调用的第一个)。之后的一切都被忽略了。

您可以将sendEmails()内的代码作为一个解决方案添加到uploadFiles()中吗?或者将其添加到成功处理程序?或者上传文件()一旦完成就调用sendEmails()......