【发布时间】:2022-01-04 17:25:47
【问题描述】:
我想使用 Firebase 存储通过 javascript 在我的网页上显示几张图片。 我用:
getDownloadURL(ref(storage, imageIndexPathRoot)).then((url) =>{
img.setAttribute('src', url);
问题是只显示最后一张图片。如果我有例如我的文件夹中有 5 张图片,带有 imageIndexPathRoot 的 getDownload 行对所有 5 张图片都正确执行,但仅在最后一张图片上执行 img.setAttribute... 行,并且该图片不会显示在网页上。
// Now we get the references of these images
listAll(listRef).then((res) => {
res.items.forEach(function(imageRef) {
// And finally display them
console.log(imageRef);
displayImage(imageRef);
});
}).catch((error) => {
// Handle any errors
console.log("Error 1");
});
function displayImage(imageRef) {
const img = document.getElementById('tierFoto');
img.src = imageRef.fullPath;
getDownloadURL(ref(storage, imageIndexPathRoot)).then((url) =>{
img.setAttribute('src', url);
})
.catch((error) => {
console.log(error);
});
}
}
【问题讨论】:
标签: javascript html firebase url firebase-storage