0

나는 바로 중포 기지의 문서에서이 코드를 가지고 :Firebase의 저장소에서 이미지의 URL을 검색하는 방법은 무엇입니까?

// 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 파일에 쓸 무엇을 알아낼 수 없습니다?

답변

1

결과를 컨트롤러의 변수와 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; 
    }); 
}]); 

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

안녕하세요, 당신의 도움을 주셔서 감사 HTML은, 내 그림 주위에 CSS를 표시하지만 사진 자체는 **하지 ** 게재 중 (아직). 나는 imageUrl에 console.log를 시도하고 nothings도 나타납니다. 그 원인은 무엇일까요? – FrenchyNYC

+0

당신이 디버깅하려고 시도하는 것은 imageUrl이 아닌'console.log (url)'을 넣는 것입니다. imageUrl을 디버그하고 싶다면'console.log ($ scope.imageUrl)'를해야한다. – e666

+0

기억이 안좋다. 이제 내가 가진 마지막 문제는 "파일"이 정의되어 있지 않다는 것입니다. 내가 어떻게이 데이터를 가질 수 있는지 아는가? 그렇지 않으면 모두 작동;) – FrenchyNYC

관련 문제