繁体   English   中英

如何从Firebase的存储中检索图像的url?

[英]How to retrieve image's url from Firebase's storage?

我直接从Firebase的文档中获得以下代码:

// Create a reference to the file we want to download
  var user = firebase.auth().currentUser.uid;
  var storageRef = firebase.storage();
  var pathReference = storageRef.ref('/' + user + '/profilePicture/' + image.name);

  //var starsRef = storageRef.child('/' + user + '/profilePicture/' + file.name);

  // Get the download URL
  pathReference.getDownloadURL().then(function(url) {
  // Insert url into an <img> tag to "download"
      $scope.imageUrl = url;
      console.log($scope.imageUrl);
  });

但是我无法弄清楚在html文件中写些什么才能得到显示...的图像,有什么帮助吗?

只需将结果放入控制器的变量中,并放在HTML的ng-src中。

最好是使用服务而不是直接在控制器中获取URL。

控制者

app.controller('MyController', ['$scope', function($scope) {
    // Create a reference to the file we want to download
    var user = firebase.auth().currentUser.uid;
    var starsRef = storageRef.child('/' + user + '/profilePicture/' + file.name);

    // Get the download URL
    starsRef.getDownloadURL().then(function(url) {
    // Insert url into an <img> tag to "download"
        $scope.imageUrl = url;
    });
}]);

的HTML

<img ng-src="{{imageUrl}}"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM