如何从Firebase的存储中检索图像的url? [英] How to retrieve image's url from Firebase's storage?

查看:63
本文介绍了如何从Firebase的存储中检索图像的url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我直接从Firebase的文档中获得了这段代码:

I have this code straight from the documentation of 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文件中写些什么,以便获得显示...任何帮助的图像?

But I can not figure what to write in my html file in order to get the image showing... Any help ?

推荐答案

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

Just put your result inside a variable of your controller and in ng-src on the HTML.

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

The best would be to use a service to get the URL and not directly in the controller.

控制器

Controller

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

HTML

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

这篇关于如何从Firebase的存储中检索图像的url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆