我正在使用一个 npm 包mail-notifier
来处理新的电子邮件,我希望能够将附件保存到文件夹中,并且 node fs 似乎能够做到这一点,但我无法弄清楚。
这是附件如何进入的示例。
{
contentType: 'application/pdf',
transferEncoding: 'base64',
contentDisposition: 'attachment',
fileName: 'somedocument.pdf',
generatedFileName: 'somedocument.pdf',
contentId: 'f0b4b8a7983590814558ce2976c71629@mailparser',
checksum: 'bc084ae645fd6e6da0aa4d74c9b95ae6',
length: 29714,
content: <Buffer 25 50 44 46 2d 31 2e 34 0a 25 d3 eb e9 e1 0a 31 20 30 20 6f 62 6a 0a 3c 3c 2f 43 72 65 61 74 6f 72 20 28 43 68 72 6f 6d 69 75 6d 29 0a 2f 50 72 6f 64 ... 29664 more bytes>
}
这是我从其他地方看到的尝试过的,但它说
mail.attachments.forEach((attachment) => {
var output = fs.createWriteStream('/example-folder/' + attachment.generatedFileName);
attachment.stream.pipe(output);
});
尽管说 stream.pipe 不是函数,但这会引发错误。
是否要将缓冲区传递给写入流?缓冲区与它有什么关系吗?