filetype
Call Signature
Section titled “Call Signature”filetype<
TInput>(config):FiletypeConfig<TInput> &object
Defined in: packages/storage/src/schema.ts:162
Define a file type with its constraints and key generation strategy.
Two forms are supported:
- Single-limit form — accepts one
acceptlist and onemaxSizestring. All accepted MIME types share the same size limit. - Per-mime form — accepts a record of named MIME groups, each with
its own
maxSize, plus a second argument for bucket/key/hooks. Use this when (for example) images must be 10 MB but PDFs may be 50 MB.
Applies defaults for optional fields: uploadable defaults to true,
replace to false, multipartThreshold to "5mb", and partSize to
"10mb".
Type Parameters
Section titled “Type Parameters”TInput
Section titled “TInput”TInput = Record<string, unknown>
The shape of caller-provided input available in the key function and hooks.
Parameters
Section titled “Parameters”config
Section titled “config”FiletypeConfig<TInput>
Returns
Section titled “Returns”FiletypeConfig<TInput> & object
The config with defaults applied, fully resolved.
Examples
Section titled “Examples”const avatars = filetype({ bucket: "UPLOADS", accept: ["image/jpeg", "image/png", "image/webp"], maxSize: "2mb", key: (file, ctx) => `avatars/${ctx.user.id}/${file.name}`,});const assets = filetype( { image: { mimes: ["image/jpeg", "image/png", "image/webp"], maxSize: "10mb" }, document: { mimes: ["application/pdf"], maxSize: "50mb" }, }, { bucket: "UPLOADS", key: (file, ctx) => `assets/${ctx.user.id}/${file.name}`, },);Call Signature
Section titled “Call Signature”filetype<
TInput>(groups,options):FiletypeConfig<TInput> &object
Defined in: packages/storage/src/schema.ts:170
Define a file type with its constraints and key generation strategy.
Two forms are supported:
- Single-limit form — accepts one
acceptlist and onemaxSizestring. All accepted MIME types share the same size limit. - Per-mime form — accepts a record of named MIME groups, each with
its own
maxSize, plus a second argument for bucket/key/hooks. Use this when (for example) images must be 10 MB but PDFs may be 50 MB.
Applies defaults for optional fields: uploadable defaults to true,
replace to false, multipartThreshold to "5mb", and partSize to
"10mb".
Type Parameters
Section titled “Type Parameters”TInput
Section titled “TInput”TInput = Record<string, unknown>
The shape of caller-provided input available in the key function and hooks.
Parameters
Section titled “Parameters”groups
Section titled “groups”options
Section titled “options”MimeGroupedFiletypeOptions<TInput>
Returns
Section titled “Returns”FiletypeConfig<TInput> & object
The config with defaults applied, fully resolved.
Examples
Section titled “Examples”const avatars = filetype({ bucket: "UPLOADS", accept: ["image/jpeg", "image/png", "image/webp"], maxSize: "2mb", key: (file, ctx) => `avatars/${ctx.user.id}/${file.name}`,});const assets = filetype( { image: { mimes: ["image/jpeg", "image/png", "image/webp"], maxSize: "10mb" }, document: { mimes: ["application/pdf"], maxSize: "50mb" }, }, { bucket: "UPLOADS", key: (file, ctx) => `assets/${ctx.user.id}/${file.name}`, },);