4

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 .

Mistalis
  • 17,793
  • 13
  • 73
  • 97
Earvin
  • 51
  • 1
  • 5
  • You need a url to all files in your firebase storage location? – kabuto178 Jan 03 '17 at 18:45
  • Can you add more details? – John Down Jan 03 '17 at 18:52
  • I normally save the firebase storage URLs in the firebase database. You can then pull these with the [firebase sdk](https://firebase.google.com/docs/web/setup). Also keep in mind that a "storage reference" is different from a "downloadUrl" - [firebase storage docs](https://github.com/firebase/quickstart-js) – Jim Jan 03 '17 at 20:11
  • thank you so much for the reply. i appreciate it . i will definitely try this one . @Jim – Earvin Jan 05 '17 at 19:33
  • @kabuto178 . yes . I want that the moment I upload files to the firebase storage, the download url will be displayed in my firebase database. – Earvin Jan 05 '17 at 19:34
  • @JohnDown. I want to get all download urls in my firebase storage and display it in my firebase database . – Earvin Jan 05 '17 at 19:36
  • Thank you all for the reply. Much Appreciated – Earvin Jan 05 '17 at 19:37
  • Possible duplicate of [Get Download URL from file uploaded with Cloud Functions for Firebase](https://stackoverflow.com/questions/42956250/get-download-url-from-file-uploaded-with-cloud-functions-for-firebase) – Thomas David Kehoe May 20 '19 at 13:12

1 Answers1

1

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);
});
Thomas David Kehoe
  • 10,040
  • 14
  • 61
  • 100
  • How in gods name does firebase not return the URL. There are thousands of SO questions asking for this because it's maybe the most basic need when it comes to media storage. Cloudinary does this. S3 does this. – A.com May 19 '19 at 12:46