Skip to content

Instantly share code, notes, and snippets.

@asciimike
Last active November 29, 2021 18:05
Show Gist options
  • Save asciimike/d4f1327b58ad69334ef06327184df790 to your computer and use it in GitHub Desktop.
Save asciimike/d4f1327b58ad69334ef06327184df790 to your computer and use it in GitHub Desktop.
Upload multiple files transactionally in Firebase Storage
// 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
});
@andreav94
Copy link

With "transactionally" , do you mean that if we upload two file and the second file upload fail for some reason, then if the first file upload was completed correctly, it will be canceled from the storage without any effort from me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment