node.js sendgrid如何附加pdf

我使用sendgrid在我的node.js应用程序中发送电子邮件。 我试图附上一个pdf的每一个组合都以我附加的pdf不可读取而告终。

我试过了:

fs.readFile('public_html/img/Report.pdf',function(err,data){ var base64data = new Buffer(data).toString('base64'); sendgrid.send({ to : hexDecode(_.e), from : 'xxxxxxxxx@gmail.com', subject : 'Report', files : [{filename:'Report.pdf',content:'data:application/pdf;base64,'+base64data}], //files : [{filename:'Report.pdf',contentType:'data:application/pdf',url:'public_html/img/'Report.pdf'}], //files : [{filename:'Report.pdf',url:'public_html/img/'Report.pdf'}], html : 'bla bla' 

有谁知道如何防止“加载PDF文档失败?

根据自述文件 ,你应该传递你的内容,而不是把它变成一个数据URI。

 fs.readFile('public_html/img/Report.pdf', function(err, data) { sendgrid.send({ to : hexDecode(_.e), from : 'xxxxxxxxx@gmail.com', subject : 'Report', files : [{filename: 'Report.pdf', content: data}], html : 'bla bla'