简体   繁体   中英

How to get all download url from firebase storage?

我是新手,我正在尝试从firebase存储中获取所有下载URL并将其显示在表格或列表中。

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, eg,

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);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM