我正在开发一个页面,并使用firebase存储作为文件存储。我尝试使用firebase开发人员文档中给出的代码,但我似乎无法使其工作。可能的问题是什么?
document.getElementById("but").addEventListener('click', e => {
// Create a reference under which you want to list
const listRef = ref(storage, 'folder/');
// Find all the prefixes and items.
listAll(listRef)
.then((res) => {
res.prefixes.forEach((folderRef) => {
// All the prefixes under listRef.
// You may call listAll() recursively on them.
});
res.items.forEach((itemRef) => {
// All the items under listRef.
console.log( getDownloadURL(ref(storage, `folder/${itemRef}`)))
})
})
});发布于 2021-11-04 13:47:17
我不确定你的代码有什么问题,但有一个错误:
res.items.forEach((itemRef) => {
// All the items under listRef.
console.log( getDownloadURL(ref(storage, `folder/${itemRef}`)))
})getDownloadURL函数执行对服务器的异步调用,因此您需要使用await或then来捕获结果:
res.items.forEach((itemRef) => {
getDownloadURL(ref(storage, `folder/${itemRef}`))
.then((downloadURL) => {
console.log(downloadURL);
});
})https://stackoverflow.com/questions/69838794
复制相似问题