Skip to content

CreateStorageRouteHandlersOptions

CreateStorageRouteHandlersOptions<T> = object

Defined in: packages/storage/src/route-handlers.ts:25

Options for createStorageRouteHandlers.

T extends StorageSchema

optional basePath: string

Defined in: packages/storage/src/route-handlers.ts:53

Base path the routes are mounted at. Defaults to "uploads". Must match the basePath passed to storageRoutes so that signed URLs resolve to the correct routes.


optional getEnv: (request) => Record<string, unknown>

Defined in: packages/storage/src/route-handlers.ts:35

Callback that returns the Workers environment for a given request.

Defaults to reading (request as any).context?.env, which works with the @cfast/core request adapter. Override this if your runtime exposes env bindings somewhere else.

Request

Record<string, unknown>


optional requireUser: (request) => Promise<StorageRouteUser> | StorageRouteUser

Defined in: packages/storage/src/route-handlers.ts:47

Authentication gate. Called on both GET (proxy) and POST (upload) requests before any R2 interaction. Return the authenticated user or throw a Response to abort. If omitted, the routes run unauthenticated — only do this if the downstream ownerCheck or signed-token check is sufficient for your threat model.

On GET requests, if requireUser is omitted and the request carries a ?token=... query parameter, the token is validated against STORAGE_SECRET instead of calling requireUser.

Request

Promise<StorageRouteUser> | StorageRouteUser


storage: StorageInstance<T>

Defined in: packages/storage/src/route-handlers.ts:27

The storage instance returned from defineStorage.