gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 05:00:57 25 4
gpt4 key购买 nike

我直接从 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 文件中写什么才能显示图像......有什么帮助吗?

最佳答案

只需将结果放入 Controller 的变量中以及 HTML 上的 ng-src 中即可。

最好是使用服务来获取 URL,而不是直接在 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

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

关于javascript - 如何从 Firebase 存储中检索图像 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42228193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com