I’m using firebase storage to store some images, however, when I want to set the source of an <img> element to the corresponding URL, it just works on some images. This is the function I’m trying to implement:
function setImgUrl (element, imgPath) {
getDownloadURL(refStorage(storage, imgPath))
.then((url) => {
element.src = url;
})
}
I’ve found through the debugger that both the element and the image url are getting correctly passed to the .then(), but when it tries to set the source it just doesn’t work. I’ve tried both with element.src = url and element.setAttribute(‘src’, url), but the result is the same. The images on which it doesn’t work seem to be random even though when I reload the page they are the same.
Lucas Franco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.