I have stored an image in a postgresql database and i have accessed that picture from database with Node.js and displayed it on the browser with
res.send(`<img src="data:${mimeType};base64,${b64}" />`);
but now i have set up a miniature REST API that only serves that picture but i do not know where to go about it, i have tried sending the whole encoded data like (src = "data:image/png;base64,......)) and then creating an IMG element and making the src of that image with that data. i am in the dark here, any help would be appreciated
app.get('/', async(req,res) => {
try {
const query = await pool.query("SELECT * FROM picture");
console.log(query.rows)
const buff = query.rows;
const b64 = buff[0].image.toString('base64');
const src = "data:image/png;base64,"+b64;
res.setHeader('Content-type', 'image/png');
res.send(src);
} catch (e) {
console.log(e.message)
}
})
Content-type: image/png. After this header, you need to send the actual binary image data.