I have an png image which I am serving from my express endpoint, the image should be readable as an image source. I have currently got the image as a buffer in node and I am trying to render it however I cannot seem to get the image to appear.
Outcome
Expected
Express JS Code
publicController.get('/avatar', async (req, res, next) => {
const image = await PUBLIC.avatar();
res.writeHead(200, {
'Content-Type': 'image/png',
'Content-Length': image.toString("binary").length
});
res.charset = 'binary';
res.write(image.toString("binary"));
res.end()
})
Tried Methods:
- Piping from a readable stream
- Convert to base 64 and render
- Convert to binary and pipe
- Convert to binary and render
- Dump raw png file
Considerations:
- I have checked and the PNG file is correct, I created a file from the buffer and the PNG renders perfectly.
- The png image is dynamic dependant on several factors hence why I cannot place in an object storage like s3.