I am converting binary file’s buffer to base64 text before storing to mongodb. I am using multer to get image alongside with with other field. I am sending those data in FormData
and the back end is
app.post('/image', multer().single('image'), (req, res) => {
const image = Buffer.from(req.file.buffer).toString('base64')
database.collection('images').insertOne({image})
}
Now, how do I decode this base64
text to binary image?
I tried this in the front end after getting the json from the back end
URL.createObjectURL(new Blob([window.atob(data.image)]))
But I think the binary file is corrupted.