In my node.js app I`m trying to respond with an image.
This image was saved before postgresql as text.
The text looks just like this:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAAE
But when I try to return it as an image:
res.type('image/png');
res.send(image_string);
Or binary:
res.send(image_string,'binary');
It shows a empty image-element:
What do I wrong?Thanks
I solved it by using a buffer:
const im = image_string.split(",")[1];
const img = Buffer.from(im, 'base64');
res.writeHead(200, {
'Content-Type': 'image/png',
'Content-Length': img.length
});
res.end(img);
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