从 firebase 存储获取下载 url 时出现问题

Problem getting the download url from firebase storage

我正在尝试循环浏览我在 firebase 上的游戏文件夹中的文件,并将它们以列表格式显示在页面上。

// Create a reference under which you want to list
var listRef = firebase.storage().ref("games/");;

// Find all the prefixes and items.
listRef.listAll().then(function(res) {
  res.prefixes.forEach(function(folderRef) {
    // All the prefixes under listRef.
    // You may call listAll() recursively on them.
  });
  res.items.forEach(function(itemRef) {
    // All the items under listRef.
    console.log(itemRef)
    const p = document.createElement('a');
    p.textContent = itemRef.location.path;
    p.classList.add('col-lg-12');
    p.href = itemRef.getDownloadURL(); 
    console.log(p.href);
    

    document.getElementById('bar').appendChild(p);
    document.getElementById('bar').innerHTML+='<br />'

  });
}).catch(function(error) {
  // Uh-oh, an error occurred!
});


问题是我得到 p.href = [object%20promise] 而不是下载 url 到我的文件。

API documentation for getDownloadURL() 说它 return 是一个用 URL 解决的承诺。它不直接return一个URL。您将不得不使用此承诺来获得 URL,就像您使用由 listAll() 编辑的承诺 return 一样。

itemRef.getDownloadURL().then(url => {
    console.log(url);
}

我建议好好看看 documentation 了解更多信息。