我正在尝试从fs 阅读pdf文件,并使用sendgrid通过电子邮件发送它。 我的文件夹结构是这样的
/
-src
--controllers
---travelplan.js
-pdf
如果我这样做,请在 travelplan.js 中
fs.readFile('pdf/204.pdf', function (err, data) {
if (err) {
console.log("THIS ERROR IS AWESOME", err)
}
})
一切正常。没问题。
但是如果这样阅读
let pdf_number = 204;
fs.readFile(`pdf/${pdf_number}.pdf`, function (err, data) {
if (err) {
console.log("THIS ERROR IS AWESOME", err)
}
})
这不起作用。 Pdf无法正确发送。
然后我尝试了
let pdf_number = 204;
var pdf_path = path.join(__dirname, '..', 'pdf',pdf_number);
fs.readFile(pdf_path, function (err, data) {
if (err) {
console.log("THIS ERROR IS AWESOME", err)
}
})
这也不起作用。
如何通过将pdf文件名作为参数传递来读取pdf文件?
任何帮助!
非常感谢。