Javascript 如何检索图像';来自Firebase的s url';什么是存储?
我直接从Firebase的文档中获得了以下代码:Javascript 如何检索图像';来自Firebase的s url';什么是存储?,javascript,angularjs,firebase,ionic-framework,firebase-storage,Javascript,Angularjs,Firebase,Ionic Framework,Firebase 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);
// 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);
});
//创建对要下载的文件的引用
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);
//获取下载URL
pathReference.getDownloadURL().then(函数(url){
//将url插入标记以“下载”
$scope.imageUrl=url;
log($scope.imageUrl);
});
但是我不知道要在我的html文件中写什么才能让图像显示。。。有什么帮助吗?只需将结果放在控制器的一个变量中,然后放在HTML的ng src中即可 最好是使用服务获取URL,而不是直接在控制器中 控制器
app.controller('MyController',['$scope',函数($scope){
//创建对要下载的文件的引用
var user=firebase.auth().currentUser.uid;
var starsRef=storageRef.child('/'+user+'/profilePicture/'+file.name);
//获取下载URL
starsRef.getDownloadURL().then(函数(url){
//将url插入到
您好,谢谢您的帮助,它在我的图片周围显示css,但图片本身没有显示(尚未显示)。我在imageUrl上尝试了一个console.log,但也没有显示任何内容。原因可能是什么?您应该试着调试的是放置一个console.log(url)
而不是imageUrl。如果您想调试imageUrl,您应该执行console.log($scope.imageUrl)
我的错,我忘记了引用存储。现在我遇到的最后一个问题是“文件”没有定义。知道如何获得此数据吗?否则一切正常;)这取决于您的代码。如果您在未定义文件之前未定义文件,则file.name将被取消定义。这应该只是firebase存储中图像的文件名
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;
});
}]);
<img ng-src="{{imageUrl}}"/>