[英]Create image file in nodeJs from blob
I am receiving BLOB
data on nodeJs server which is converted from PNG image. 我在nodeJs服务器上接收从PNG图像转换的
BLOB
数据。
I need to create again png image on nodeJs server to be able to show it on pdf document. 我需要在nodeJs服务器上再次创建png图像才能在pdf文档上显示它。
I had tried to use FileSaver on nodeJs but it is not working. 我曾尝试在nodeJs上使用FileSaver,但它无法正常工作。 FileSaver works well on reactJs app.
FileSaver在reactJs应用程序上运行良好。
How can I save a new file to the local directory on the server? 如何将新文件保存到服务器上的本地目录?
There is a lot question pointing on problems with creating an image file form blob but I was unable to use base64encode, so other questions were not helpful.
关于创建图像文件表单blob的问题有很多问题,但我无法使用base64encode,因此其他问题没有帮助。
In BLOB data of png image file there is buffer
property. 在png图像文件的BLOB数据中有
buffer
属性。
So I used this solution to create image. 所以我使用这个解决方案来创建图像。
var imageBuffer = request.file.buffer;
var imageName = 'public/images/map.png';
fs.createWriteStream(imageName).write(imageBuffer);
This has solved my problem. 这解决了我的问题。
var base64Data = req.body.image.replace(/^data:image\/png;base64,/, "");
require("fs").writeFile("out.png", base64Data, 'base64', function(err) {
console.log(err);
});
Try this one here image is the name on which data is coming. 在这里尝试这个图像是数据来源的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.