Skip to content

StorageInstance

StorageInstance<T> = object

Defined in: packages/storage/src/types.ts:230

The storage instance returned by defineStorage, providing upload, serve, and URL methods.

All methods are scoped to the declared schema — TypeScript enforces that file type names and input types match the schema definition.

const storage = defineStorage({ avatars: filetype({ ... }) });
// Upload
const result = await storage.handle("avatars", request, { env, user });
// Serve
const response = await storage.serve("avatars", result.key, { env });
// Client config for StorageProvider
const config = storage.clientConfig();

T extends StorageSchema

The storage schema type mapping file type names to their configs.

clientConfig: () => ClientStorageConfig

Defined in: packages/storage/src/types.ts:248

Extract the client-safe subset of the schema for use with StorageProvider.

ClientStorageConfig


getPublicUrl: (name, key) => string

Defined in: packages/storage/src/types.ts:242

Build a public URL for a file in a public bucket.

keyof T & string

string

string


getSignedUrl: (name, key, options) => Promise<string>

Defined in: packages/storage/src/types.ts:244

Generate a time-limited HMAC-signed URL for private file access.

keyof T & string

string

SignedUrlOptions

Promise<string>


handle: <K>(name, request, ctx) => Promise<UploadResult>

Defined in: packages/storage/src/types.ts:234

Parse, validate, and upload a file from an incoming request to R2.

K extends keyof T & string

K

Request

HandleContext<T[K] extends FiletypeConfig<infer I> ? I : Record<string, unknown>>

Promise<UploadResult>


schema: T

Defined in: packages/storage/src/types.ts:232

The raw schema passed to defineStorage.


serve: (name, key, options) => Promise<Response>

Defined in: packages/storage/src/types.ts:240

Stream a file directly from R2, returning a Response with appropriate headers.

keyof T & string

string

ServeOptions

Promise<Response>


verifySignedUrl: (url, options) => Promise<boolean>

Defined in: packages/storage/src/types.ts:246

Verify that a signed URL has a valid signature and has not expired.

string

Record<string, unknown>

Promise<boolean>