如何将node.js可读流附加到SendGrid电子邮件中? [英] How to attach a node.js readable stream to a Sendgrid email?
本文介绍了如何将node.js可读流附加到SendGrid电子邮件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
sendgrid.send({
to: email,
files: [{ filename: 'File.pdf', content: /* what to put here? */ }]
/* ... */
});
我已尝试doc.output()
,但没有效果。
推荐答案
要对流文件使用SendGrid NodeJS API,只需将流转换为缓冲区即可。您可以使用流到数组将可读流转换为缓冲区。
var streamToArray = require('stream-to-array');
streamToArray(your_stream, function (err, arr) {
var buffer = Buffer.concat(arr)
sendgrid.send({
to: email,
files: [{ filename: 'File.pdf' content: buffer }]
})
})
这篇关于如何将node.js可读流附加到SendGrid电子邮件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文