I am receiving BLOB
data on nodeJs server which is converted from PNG image.
I need to create again png image on nodeJs server to be able to show it on pdf document.
I had tried to use FileSaver on nodeJs but it is not working. FileSaver works well on reactJs app.
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.
getContext("2d"); // Get the "context" of the canvas var img = document. getElementById("myimage"); // The id of your image container ctx. drawImage(img,0,0,width,height); // Draw your image to the canvas var jpegFile = canvas. toDataURL("image/jpeg"); // This will save your image as a //jpeg file in the base64 format.
To convert Blob to File in JavaScript, we can use the File constructor. const file = new File([myBlob], "name"); to create a File object with the myBlob blob object in the array. The 2nd argument is the file name string.
To write an image to a local server with Node. js, we can use the fs. writeFile method. to call res.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With