Skip to content
Files SDK
Esc
navigateopen⌘Jpreview
On this page

Firebase Storage

Firebase Cloud Storage via the official firebase-admin SDK. Underlying client is @google-cloud/storage, so V4 signed URLs and POST policy uploads come for free.

Installation

firebase-admin is an optional peer dependency of files-sdk - install alongside the SDK so the adapter’s imports resolve at runtime.

npm install files-sdk firebase-admin
pnpm add files-sdk firebase-admin
yarn add files-sdk firebase-admin
bun add files-sdk firebase-admin

Usage

Firebase Cloud Storage via the official firebase-admin SDK. The Admin SDK’s getStorage().bucket() returns a @google-cloud/storage Bucket under the hood, so every primitive (server-side copy, V4 signed URLs, POST policy uploads) maps onto the GCS surface - with Firebase-flavoured credential conventions and a default bucket name derived from your project ID.

import { Files } from "files-sdk";
import { firebaseStorage } from "files-sdk/firebase-storage";

const files = new Files({
  adapter: firebaseStorage({
    bucket: "my-project.firebasestorage.app",
    // Auto-loads credentials from FIREBASE_PROJECT_ID,
    // FIREBASE_CLIENT_EMAIL, FIREBASE_PRIVATE_KEY, or falls back to
    // Application Default Credentials (GOOGLE_APPLICATION_CREDENTIALS,
    // gcloud auth, GCE metadata). Or pass an existing firebase-admin App
    // or @google-cloud/storage Bucket via `app`.
  }),
});

upload reports true byte-level progress via onProgress. As with GCS, passing onProgress switches the upload to a resumable request (the only path that emits progress), which adds one round trip.

Options

PropType
bucket?string

Storage bucket name. Falls back to `FIREBASE_STORAGE_BUCKET`, then `<projectId>.firebasestorage.app` if `projectId` is known. The Firebase console shows the bucket as `<project>.appspot.com` on older projects and `<project>.firebasestorage.app` on newer ones — pass the literal name from the console rather than relying on the default.

Typestring
projectId?string

GCP project ID. Falls back to `FIREBASE_PROJECT_ID`, then `GOOGLE_CLOUD_PROJECT`, then `GCLOUD_PROJECT`. Optional — Application Default Credentials carry a project ID and the SDK will discover it automatically.

Typestring
credentials?{ clientEmail: string; privateKey: string }

Inline service-account credentials. Useful when you only have `clientEmail` + `privateKey` available as separate env vars (e.g. Vercel/Netlify) and don't want to materialize a JSON file. When neither this nor `serviceAccountPath` is set, the SDK falls back to ADC. Falls back to `FIREBASE_CLIENT_EMAIL` + `FIREBASE_PRIVATE_KEY`.

Type{ clientEmail: string; privateKey: string }
serviceAccountPath?string

Path to a service-account JSON file. When set, takes precedence over inline `credentials`. Falls back to `GOOGLE_APPLICATION_CREDENTIALS`.

Typestring
app?App | Bucket

Existing Firebase {@link App} or `@google-cloud/storage` {@link Bucket}. Highest precedence — when passed, all other credential options are ignored. Useful when the consumer already initializes Firebase elsewhere (e.g. for Firestore/Auth) and wants to share the app.

TypeApp | Bucket
publicBaseUrl?string

Origin used to build URLs from `url()`. When set, `url(key)` returns `${publicBaseUrl}/${key}` and skips signing — appropriate for a public bucket or a CDN in front of Firebase Storage. When unset, `url()` falls back to a V4 signed read URL (default expiry: 1 hour). Firebase's `?alt=media&token=...` download-token URL form is out of scope for v1; reach for `adapter.raw` if you need it.

Typestring
defaultUrlExpiresIn?number

Default expiry, in seconds, for the V4 signed URLs returned by `url()` when `publicBaseUrl` is not set. Defaults to 3600 (1 hour). Per-call `url(key, { expiresIn })` overrides. GCS V4 caps at 7 days.

Typenumber
appName?string

Internal Firebase app name. Allows multiple adapter instances pointing at different projects to coexist without the `initializeApp()` "default app already exists" error. Defaults to a stable name derived from the project ID and bucket; only set this if you have a reason.

Typestring

Limitations

Firebase’s ?alt=media&token=... download-token URL form is out of scope for v1 - url() always returns either a V4 signed read URL or your configured publicBaseUrl. Reach for adapter.raw (the underlying @google-cloud/storage Bucket) if you need to mint Firebase download tokens or use any GCS-side feature that isn’t in the unified API. Stream uploads use single-request mode; multi-GB resumable uploads also need raw.

Compatibility

Method Status Notes
upload
download
delete
list
search
head
exists
copy
url
signedUploadUrl

Was this page helpful?