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.
Example
Section titled “Example”const storage = defineStorage({ avatars: filetype({ ... }) });
// Uploadconst result = await storage.handle("avatars", request, { env, user });
// Serveconst response = await storage.serve("avatars", result.key, { env });
// Client config for StorageProviderconst config = storage.clientConfig();Type Parameters
Section titled “Type Parameters”T extends StorageSchema
The storage schema type mapping file type names to their configs.
Properties
Section titled “Properties”clientConfig()
Section titled “clientConfig()”clientConfig: () =>
ClientStorageConfig
Defined in: packages/storage/src/types.ts:248
Extract the client-safe subset of the schema for use with StorageProvider.
Returns
Section titled “Returns”getPublicUrl()
Section titled “getPublicUrl()”getPublicUrl: (
name,key) =>string
Defined in: packages/storage/src/types.ts:242
Build a public URL for a file in a public bucket.
Parameters
Section titled “Parameters”keyof T & string
string
Returns
Section titled “Returns”string
getSignedUrl()
Section titled “getSignedUrl()”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.
Parameters
Section titled “Parameters”keyof T & string
string
options
Section titled “options”Returns
Section titled “Returns”Promise<string>
handle()
Section titled “handle()”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.
Type Parameters
Section titled “Type Parameters”K extends keyof T & string
Parameters
Section titled “Parameters”K
request
Section titled “request”Request
HandleContext<T[K] extends FiletypeConfig<infer I> ? I : Record<string, unknown>>
Returns
Section titled “Returns”Promise<UploadResult>
schema
Section titled “schema”schema:
T
Defined in: packages/storage/src/types.ts:232
The raw schema passed to defineStorage.
serve()
Section titled “serve()”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.
Parameters
Section titled “Parameters”keyof T & string
string
options
Section titled “options”Returns
Section titled “Returns”Promise<Response>
verifySignedUrl()
Section titled “verifySignedUrl()”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.
Parameters
Section titled “Parameters”string
options
Section titled “options”Record<string, unknown>
Returns
Section titled “Returns”Promise<boolean>