I have an HTML file loaded into an S3 bucket. This file is intended to be used as a template for the body of an email.
I used one of the answers from this question (Read file from aws s3 bucket using node fs) to help me get the file out of the bucket. Now it appears I have buffer data that I need to convert back into HTML, or a string version of it would also be fine. Things I've tried so far haven't worked...
Here's what my code getting the template looks like:
async getEmailTemplate() {
const s3 = new AWS.S3({ apiVersion: '2006-03-01' });
const params = {
Bucket: 'myBucket',
Key: 'templates/email.html',
};
const template = await s3.getObject(params).promise();
return template;
}
When I log the data that "template" returns, it appears like this... I need something like template.body.toString('latin1')...
console.log src/services/tests/unit/Controller.test.js:266
{
AcceptRanges: 'bytes',
LastModified: 2020-05-28T19:36:23.000Z,
ContentLength: 22745,
ETag: '"1bcc123ba55b5b878109436c1274b94b"',
ContentType: 'text/html',
Metadata: {},
Body: <Buffer 3c 21 44 4f 43 54 59 50 45 20 68 74 6d 6c 3e 0a 3c 68 74 6d 6c 20 78 6d 6c 6e 73 3a 76 3d 22 75 72 6e 3a 73 63 68 65 6d 61 73 2d 6d 69 63 72 6f 73 6f ... 22695 more bytes>
}
In case it makes a difference, the template contains js template literals that look like ${data.firstName}. Currently the email is correctly getting populated and sent when the template is hardcoded in the javascript file with `` surrounding it. But I'm trying to update the code to pull the template from an external source instead.
Thank you for taking the time to read my question... Does anyone have suggestions for me? :)