Reputation: 51
I'm a newbie and I am trying to get all download url from firebase storage and display it in a table or a list .
Upvotes: 4
Views: 2748
Reputation: 10930
The download URL isn't provided in the snapshot
you receive when your file is uploaded to Storage. It'd be nice if Firebase provided this.
To get the download URL you use the method getDownloadURL()
on your file's storage reference. There are two types of storage references, firebase.storage.ref()
and firebase.storage.refFromURL(
. The former uses the path to the file, which is provided in the snapshot
after your file is uploaded to Storage. The latter uses either a Google Cloud Storage URI or a HTTPS URL, neither of which is provided in the snapshot
. If you want to get the download URL immediately after uploading a file, you'll want to use firebase.storage.ref()
and the file's path, e.g.,
firebase.storage.ref('English_Videos/Walker_Climbs_a_Tree/Walker_Climbs_a_Tree_3.mp4');
Here's the full code for uploading a file to Storage and getting the download URL:
firebase.storage().ref($scope.languageVideos + "/" + $scope.movieOrTvShow + "/" + $scope.videoSource.name).put($scope.videoSource, metadata) // upload to Firebase Storage
.then(function(snapshot) {
console.log("Uploaded file to Storage.");
firebase.storage().ref(snapshot.ref.location.path).getDownloadURL() // get downloadURL
.then(function(url) {
var $scope.downloadURL = url;
})
.catch(function(error) {
console.log(error);
});
})
.catch(function(error) {
console.log(error);
});
Upvotes: 1