首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >列出firebase存储v9中的所有文件

列出firebase存储v9中的所有文件
EN

Stack Overflow用户
提问于 2021-11-04 11:50:44
回答 1查看 108关注 0票数 0

我正在开发一个页面,并使用firebase存储作为文件存储。我尝试使用firebase开发人员文档中给出的代码,但我似乎无法使其工作。可能的问题是什么?

代码语言:javascript
复制
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}`)))
            })
        })
});
EN

回答 1

Stack Overflow用户

发布于 2021-11-04 13:47:17

我不确定你的代码有什么问题,但有一个错误:

代码语言:javascript
复制
res.items.forEach((itemRef) => {
    // All the items under listRef.
    console.log( getDownloadURL(ref(storage, `folder/${itemRef}`)))
})

getDownloadURL函数执行对服务器的异步调用,因此您需要使用awaitthen来捕获结果:

代码语言:javascript
复制
res.items.forEach((itemRef) => {
    getDownloadURL(ref(storage, `folder/${itemRef}`))
        .then((downloadURL) => {
            console.log(downloadURL);
        });
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69838794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档