【问题标题】:how to get url array after uploading multiple file to firebase storage in js如何在js中将多个文件上传到firebase存储后获取url数组
【发布时间】:2020-04-15 18:19:40
【问题描述】:

如何在将多个文件上传到 Firebase 存储后获取 url 数组。我正在使用下面的代码,但它返回元数据数组。

firebase.storage().ref().constructor.prototype.putFiles = function(files) { 
  var ref = this;
  return Promise.all(files.map(function(file) {
  return ref.child(file.name).put(file);
  }));
}

// use it!
firebase.storage().ref().putFiles(files).then(function(metadatas) {
 // Get an array of file metadata
 }).catch(function(error) {
 // If any task fails, handle this
});

【问题讨论】:

    标签: reactjs firebase firebase-storage


    【解决方案1】:

    最简单的方法是在上传每个文件后返回下载 URL而不是元数据:

    return Promise.all(files.map(function(file) {
      return ref.child(file.name).put(file).then(function() {
        return ref.child(file.name).getDownloadURL();
      })
    }));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-12
      • 2017-09-24
      • 2017-07-08
      • 1970-01-01
      • 1970-01-01
      • 2018-10-17
      • 1970-01-01
      • 2018-01-24
      相关资源
      最近更新 更多