假设您的PDF文件在S3中。
从S3获取文件
const pdfFile = await s3
.getObject({
Bucket: PDF_BUCKET_NAME,
Key: `flight-${fileName}.pdf`,
})
.promise();
一旦你有了文件
const base64data = pdfFile.Body.toString('base64');
const data = {
from: 'text@example.in',
to: user.emailId,
subject: 'Your ticket for flight PNR XYSSA1 from DEL-BLR',
html: `Please find attached your ticket
<br><br>Regards<br>
Team Example`,
attachments: [
{ content: base64data, filename: 'flight-ticket', type: 'application/pdf', disposition: 'attachment' },
],
};
await sgMail.send(data);
如果文件系统中有您的文件,只需从fs.readFile获取缓冲区,将其转换为base64,如上图所示,然后重复这些步骤,您就可以开始了。