Reputation: 6259
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
Upvotes: 7
Views: 16575
Reputation: 6259
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);
Upvotes: 29