firebase-storage-kit

Batch uploads

Upload many files at once with concurrency and error handling.

Use batch uploads when the user selects multiple files — photo galleries, document folders, or bulk imports. One call starts every file; you control how many run in parallel.

Basic batch

const batch = manager.uploadFiles(
  files,
  (file) => ({ path: `uploads/${file.name}` }),
  { concurrency: 3, continueOnError: true }
);

batch.on("progress", (snapshot) => {
  console.log(`${Math.round(snapshot.totalProgress * 100)}% overall`);
});

batch.on("success", (snapshot) => {
  console.log(
    `${snapshot.completedCount} done, ${snapshot.failedCount} failed`
  );
});

Arguments

  1. files — array of browser File objects
  2. optionsFor — function that returns UploadOptions per file (path, retry, metadata)
  3. batchOptions (optional) — concurrency and error behavior

Batch options

OptionDefaultDescription
concurrency3Max simultaneous uploads
continueOnErrortrueKeep other files running if one fails

continueOnError: true (default)

Other files keep uploading when one fails. When every file has finished, the batch fires success. Check each child upload's status to see which succeeded or failed.

continueOnError: false

The first failure stops remaining files and the batch fires error.

Batch events

EventPayloadWhen
progressUploadBatchAggregate progress changed
changeUploadBatchAny batch property changed
uploadSuccessUploadItemOne file succeeded
uploadErrorUploadItemOne file failed
uploadRetryretry detailsOne file is retrying
successUploadBatchAll files settled (normal end)
errorUploadBatchBatch stopped due to failure (continueOnError: false)

Per-file options in a batch

manager.uploadFiles(
  files,
  (file, index) => ({
    path: `users/${userId}/${file.name}`,
    customMetadata: { index: String(index) },
    validate: { maxSizeBytes: 10 * 1024 * 1024 },
    retry: { maxRetries: 5 },
  }),
  { concurrency: 2 }
);

Pause and resume the batch

batch.pause();
batch.resume();

This pauses or resumes all active child uploads in the batch.

Snapshot

const snapshot = batch.snapshot();
// { id, uploads, totalProgress, completedCount, failedCount }

On this page