问题描述
我使用 google.script.run 在Google应用脚本中使用 MailApp API ,并且传递了这样的邮件对象:
I use google.script.run to use the MailApp API in google app script and I pass a mail object like this :
google.script.run.sendMail(mail);
邮件对象的结构如下:
var mail = {
to:"",
cc:"",
subject:"",
htmlBody:"",
inlineImages: inlineImages
}
inlineImages 是一个Javascript对象,可将密钥字符串映射到来自图像数据(BlobSource)" .google.com/apps-script/reference/mail/mail-app"rel =" nofollow noreferrer> Google资源
inlineImages is a Javascript object that map key string to image data (BlobSource) from google ressources
但是随后我在 inlineImages 中传递了 File 对象,我得到由于非法值而失败.
But then I pass File object in inlineImages I get Failed due to illegal value.
我得到这样的 inlineImages :
var inlineImages
function createImages(event) {
var file = event.target.files[0];
var key = "image"+Object.keys(inlineImages).length;
inlineImages[key] = file;
}
我也尝试获取Image对象:
I also try to get Image object :
function createImages(event) {
var file = event.target.files[0];
var key = "image"+Object.keys(inlineImages).length;
var reader = new FileReader();
reader.onload = function(e) {
var img = new Image();
img.src = e.target.result;
inlineImages[key] = img;
}
reader.readAsDataURL(file);
}
推荐答案
FileObject
不是合法值.
要通过文件从客户端到服务器通过上述限制,获取文件的唯一方法是将fileObject转换为上述类型之一.我将使用表单:
The only way you're going to get a file past through the above restrictions from client to server are if you convert the fileObject to one of the above types. I'll go with form: