簡體   English   中英

從 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 下載到我的文件中。

getDownloadURL() 的 API 文檔說它返回一個 promise,它可以用 URL 解析。 它不會直接返回 URL。 您將不得不使用此 promise 來獲取 URL,就像您使用由listAll()返回的 promise 一樣。

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

我建議仔細查看文檔以獲取更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM