我在 nodeJs 服务器上接收从 PNG 图像转换而来的 BLOB
数据。
我需要在 nodeJs 服务器上再次创建 png 图像,以便能够在 pdf 文档上显示它。
我曾尝试在 nodeJs 上使用 FileSaver,但它不起作用。 FileSaver 在 reactJs 应用程序上运行良好。
如何将新文件保存到服务器上的本地目录?
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.
最佳答案
在png图像文件的BLOB数据中有buffer
属性。
所以我使用这个解决方案来创建图像。
var imageBuffer = request.file.buffer;
var imageName = 'public/images/map.png';
fs.createWriteStream(imageName).write(imageBuffer);
这解决了我的问题。
关于javascript - 从 blob 在 nodeJs 中创建图像文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51709358/