Skip to content

defineStorage

defineStorage<T>(schema): StorageInstance<T>

Defined in: packages/storage/src/schema.ts:102

Create a type-safe storage instance from a schema of named file types.

The returned instance provides handle (upload), serve, getPublicUrl, getSignedUrl, verifySignedUrl, and clientConfig methods that are all scoped to the declared schema.

T extends StorageSchema

The storage schema type, inferred from the schema argument.

T

A record mapping file type names to their FiletypeConfig.

StorageInstance<T>

A StorageInstance with methods for uploads, serving, and URL generation.

import { defineStorage, filetype } from "@cfast/storage";
export const storage = defineStorage({
avatars: filetype({
bucket: "UPLOADS",
accept: ["image/jpeg", "image/png", "image/webp"],
maxSize: "2mb",
key: (file, ctx) => `avatars/${ctx.user.id}/${file.name}`,
replace: true,
}),
});