I uploaded an image to mongoose and the it was saved as a binary data like so:
Now Im trying to retrieve that image and display within my HTML page like so:
<img id="user-img" src="data:image/png;base64, {{base64String}}">
I have tried the following:
I am trying to convert the binary image server side before sending the user all the data.
let getOne = (req, res) => {
User.findById(req.params.id)
.exec()
.then((data) => {
if (data) {
data.photo = new Buffer(data.photo.toString(), 'base64');
sendJsonResponse(res, 200, data)
} else if (!data) {
sendJsonResponse(res, 404, {"message": "Unable to find a single user"})
}
})
.catch(err => {
sendJsonResponse(res, 500, err)
})
};
At this point the server crashes and gives a Internal Server Error 500
What am I doing wrong?
Update:
Update: