Meteor-Meteor CollectionFS-截取文件,以便通过电子邮件发送并保存
我正在使用Meteor CollectionFS上传pdf文件。它使用S3存储它,这一切都正常工作。我的问题涉及如何截取文件并将其转换为base64String,以便使用Mandrill将此pdf的副本通过电子邮件发送给用户,并将其存储以备将来使用 以下是我目前掌握的代码:Meteor-Meteor CollectionFS-截取文件,以便通过电子邮件发送并保存,meteor,base64,pdf-generation,mandrill,collectionfs,Meteor,Base64,Pdf Generation,Mandrill,Collectionfs,我正在使用Meteor CollectionFS上传pdf文件。它使用S3存储它,这一切都正常工作。我的问题涉及如何截取文件并将其转换为base64String,以便使用Mandrill将此pdf的副本通过电子邮件发送给用户,并将其存储以备将来使用 以下是我目前掌握的代码: Template.dropzone.events({ 'dropped #dropzone': function(e) { FS.Utility.eachFile(e, function(file)
Template.dropzone.events({
'dropped #dropzone': function(e) {
FS.Utility.eachFile(e, function(file) {
Meteor.call('testEmailUpload', file.toString('base64'));
var newFile = new FS.File(file);
Images.insert(newFile, function (error, fileObj) {
if (error) {
toastr.error("Upload failed... please try again.");
} else {
toastr.success('Upload succeeded!');
}
});
});
}
});
用于发送电子邮件的方法调用
'testEmailUpload': function (base64String){
Mandrill.messages.send({
message: {
subject: 'Test Email',
from_email: "xxxxxxxx",
from_name: "xxxxxxxx",
to: [{ email: "xxxxxxxx"}],
text: "TestEmail Upload Files",
headers: {"Reply-To": "xxxxxxxx" },
attachments: [{
type: "application/pdf",
name: "TestPDF.pdf",
content: base64String
}]
}
},
function(result) {
}, function(e) {
// Mandrill returns the error as an object with name and message keys
console.log('A mandrill error occurred: ' + e.name + ' - ' + e.message);
// A mandrill error occurred: Unknown_Subaccount - No subaccount exists with the id 'customer-123'
});
}
这适用于上传,没有问题。但是,我不知道应该调用什么来获取要传递到该方法的实际base64string。电子邮件现在正在发送,但是pdf从未正确创建
非常感谢您的帮助