How to upload multiple files to Firebase?

前端 未结 8 1881
既然无缘
既然无缘 2020-12-04 16:44

Is there a way to upload multiple files to Firebase storage. It can upload single file within single attempt as follows.

fileButton.addEventListener(\'chang         


        
8条回答
  •  误落风尘
    2020-12-04 17:31

    I believe there's a simpler solution:

    // set it up
    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
    });
    

提交回复
热议问题