【问题标题】:How can I get Firebase Storage data如何获取 Firebase 存储数据
【发布时间】:2020-02-21 06:41:09
【问题描述】:

这就是我的 Firebase 存储的样子,我想获取这些文件名,但我无法这样做, 我在下面分享我的代码,

const files = firebase.storage().ref(`pdf`);
                console.log(files)
                files.getDownloadURL().then((files) => {
                    console.log(files);
                })

如果我给出了确切的名称,那么我可以得到文件,比如,

const files = firebase.storage().ref('pdf/5b8e28a8-fe06-4312-9ff6-3c9adfefb2b3.pdf/');
        files.getDownloadURL().then((url) => {
          //console.log(url);
          window.open(url, "_blank")
        })
      } 

我在控制台中收到此错误,

谁能解释我在这里做错了什么

【问题讨论】:

标签: reactjs firebase firebase-storage


【解决方案1】:

正如 Doug 所说,对于 get a list of the files/subfolders,您使用 listAll()

要获取 PDF 文件夹中的文件列表:

// Create a reference under which you want to list
const files = firebase.storage().ref('pdf');

// Find all the prefixes and items.
files.listAll().then(function(res) {
  Promise.all(res.items.map((fileRef) => fileRef.getDownloadURL())).then((downloadURLs) => {
    console.log(downloadURLs);
  });
}).catch(function(error) {
  // Uh-oh, an error occurred!
});

【讨论】:

  • 感谢@Frank,但我得到了 listAll() 不是函数的错误。
  • 这通常意味着您使用的 SDK 版本尚不包含列出文件的功能。您需要升级到最新的 SDK 版本。
猜你喜欢
  • 2019-08-14
  • 2019-06-27
  • 2020-09-23
  • 2020-09-24
  • 1970-01-01
  • 2019-11-07
  • 2020-07-15
  • 2020-12-09
  • 2018-03-03
相关资源
最近更新 更多