问题描述:

I am using Meteor-CollectionFS to do a file upload of a pdf. It is storing it using S3 and this is all working. My question pertains to how can I intercept the file and convert it to a base64String so that I can use Mandrill to email a copy of this pdf to the user as well as store it for future.

Below is the code that I have so far:

 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!');

}

});

});

}

});

Method Call for the sending of the email.

'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'

});

}

This works for the uploading no problems. However I have no clue what I should be calling to get an actual base64string to pass into that method. The emails right now are sending however the pdf is never created properly.

Any help is greatly appreciated.

相关阅读:
Top