I store images im mongoDB like this:
img: {
contentType: "image/png"
data: {
data: Array(135239),
type: "Buffer"
}
}
Then i got them on frontend and trying to use in html img tag, but there are no pictures I have tried to transform the data to
let blob = new Blob([img.data], {type : img.contentType})
let img = document.createElement('img').setAttribute('src', URL.createObjectURL(blob))
let container = document.getElementById('container')
container.appendChild(img)
or
let img = document.createElement('img').setAttribute('src', `data:${img.contentType};base64,${img.data}`)
let container = document.getElementById('container')
container.appendChild(img)
but none of it does not seem to work
P.S. In the guide was written i should transform img.data.toString('base64'), but it does not work too