Skip to main content
BunnyStorage is the Storage component’s Bunny backend. It implements the IStorage interface directly against the Bunny Storage SDK, uploading and downloading files to a regional storage zone over HTTPS. That makes it a good fit for edge file delivery paired with Bunny’s CDN. Because it shares the IStorage contract with the filesystem and S3-compatible backends, you can switch to or from Bunny without changing a single call site.

What this backend gives you

Your files live in a Bunny Storage zone close to your users and pair naturally with Bunny’s CDN. The interface is the same IStorage you already know: put, getFile, getAsJson, delete, list, and the rest, identical to every other storage backend. You choose from nine storage regions with a short region code. put() takes a range of inputs (strings, ArrayBuffer, Blob, Request/Response, and BunFile/S3File) and converts each to a stream for upload. The class registers with @decorator.storage() and resolves from the container.

Installation

BunnyStorage ships with @talosjs/storage and depends on the Bunny Storage SDK.

Environment variables

Credentials are validated when BunnyStorage is constructed, so a missing key or zone fails fast at startup.

Regions

STORAGE_BUNNY_REGION accepts a short code that maps to a Bunny storage region:

How it works

BunnyStorage connects to your storage zone with the access key and chosen region, then organizes files under a bucket. The active bucket becomes a path prefix: with bucket uploads, a key avatars/1.png is stored at /uploads/avatars/1.png. Content passed to put() is converted to a ReadableStream and uploaded through the Bunny SDK. Reads stream back and are materialized as JSON, an ArrayBuffer, a stream, or written to disk.

Usage

The API is the same as every other storage backend.
Upload a local file or a whole directory, and stream large files instead of buffering them:

Use in the app

In an @talosjs/app application, storage isn’t a dedicated App config slot. BunnyStorage registers itself with the container through @decorator.storage() as soon as the class is imported, and you inject it wherever you read or write files.
Inject it into a service or controller, set the bucket, and use the IStorage methods:
To bind a dedicated bucket to its own injectable type, register a subclass with @decorator.storage():
Set STORAGE_BUNNY_ACCESS_KEY, STORAGE_BUNNY_STORAGE_ZONE, and (optionally) STORAGE_BUNNY_REGION in your .env.yml (or environment) so the backend can connect.

Exceptions

BunnyStorage throws StorageException on misconfiguration or a failed operation, carrying a machine-readable key.

Keeping uploads predictable

Call setBucket() before any read or write so keys land under the right path prefix. Set STORAGE_BUNNY_REGION to the zone closest to your users to keep latency down. Group objects under stable prefixes like avatars/123.png, which keeps list() and clearBucket() predictable. For anything large, reach for getAsStream() and putFile/putDir instead of loading whole files into memory, and pass a filter regex to putDir() when you only want a subset of a directory. Keep the access key and zone in .env rather than hard-coding them. See the Storage component for the full interface and the other backends, including Cloudflare Storage.