Firebase 存储 getDownloadURL() 不返回工作 url

新手上路,请多包涵

我尝试使用 getDownloadURL() 方法来检索存储在 firebase 存储中的图像的 url。

奇怪的是它返回一个对象的 url,而不是图像

↓↓↓切续↓切切州切切CCCAIL ↓↓↓↓↓↓↓↓↓↓↓↓ https://firebasestorage.googleapis.com/v0/b/example.appspot.com/o/images%2Fcat.png ↑↑↑↑↑↑↑↑↑↑↑↑ ^ ↑

我在网上做了一些研究,发现显示我的图片的正确网址应该是这样的……

↓↓↓切续↓切切州切切CCCAIL ↓↓↓↓↓↓↓↓↓↓↓↓ https://firebasestorage.googleapis.com/v0/b/example.appspot.com/o/images%2Fcat.png?alt=media&token=sometoken

^ ↑↑↑↑↑↑↑↑↑↑↑↑↑

但我不知道如何使用 getDownloadURL() 获取 url …

这是我的代码…

 var storage = firebase.storage();

$scope.getImgUrl = function(file) {
    storage.ref("images/" + file + ".png")
      .getDownloadURL()
      .then(function onSuccess(url) {
        return url;
      })
      .catch(function onError(err) {
        console.log("Error occured..." + err);
      })
  }

任何想法?

原文由 LeoCantThinkofAName 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 263
1 个回答

所以从 Firebase 获取图片 url 的正确方法是这样的:

  $scope.getImgUrl = function(file) {
        storage.child("images/" + file +".png").getDownloadURL().then(function(url) {
          return url;
        }).catch(function(error) {
          // Handle any errors here
        });
 }

请注意,您使用的是 storage.child() 而不是 storage.ref()

原文由 Sub 6 Resources 发布,翻译遵循 CC BY-SA 3.0 许可协议

推荐问题