如何将流中的流转换为typecript中的nodejs
我正在使用Axis下载如下:
private async downloadImage(imageUrl: string): Promise<Stream> {
const response = await axios.get<Stream>(imageUrl, {
headers: {
'Content-Type': 'image/jpeg',
},
responseType: 'stream',
});
return response.data;
}
如何将“流”对象转换为“ base64 String”,我从Nodejs中的此静止API中获得?因为我需要附加此图像,以将邮件(由NodeMailer)发送给用户。例如,
attachments: [
{
filename: 'image.jpg',
path: 'data:image/png;base64,[base64Image]',
cid: 'image',
},
],
如何在打字稿中为Nodejs实现它?
I'm using axis to download the image as following:
private async downloadImage(imageUrl: string): Promise<Stream> {
const response = await axios.get<Stream>(imageUrl, {
headers: {
'Content-Type': 'image/jpeg',
},
responseType: 'stream',
});
return response.data;
}
How can I convert the "Stream" object to "base64 string" I get from this RESTFul API in NodeJS? Because I need to attach this image to send the mail (by nodemailer) to the user. Example,
attachments: [
{
filename: 'image.jpg',
path: 'data:image/png;base64,[base64Image]',
cid: 'image',
},
],
How can I achieve it for NodeJS in TypeScript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我发现通过通过流进行转换的方法:
但是,可以使用一次流...有人知道如何克隆它再次消耗它吗?
Finally, I find the method to convert it by pass through the Stream:
However, the Stream could be used once... Anyone know how to clone it to consume it again?