Skip to content

filetype

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:

  1. Single-limit form — accepts one accept list and one maxSize string. All accepted MIME types share the same size limit.
  2. 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".

TInput = Record<string, unknown>

The shape of caller-provided input available in the key function and hooks.

FiletypeConfig<TInput>

FiletypeConfig<TInput> & object

The config with defaults applied, fully resolved.

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}`,
},
);

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:

  1. Single-limit form — accepts one accept list and one maxSize string. All accepted MIME types share the same size limit.
  2. 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".

TInput = Record<string, unknown>

The shape of caller-provided input available in the key function and hooks.

MimeGroupsRecord

MimeGroupedFiletypeOptions<TInput>

FiletypeConfig<TInput> & object

The config with defaults applied, fully resolved.

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}`,
},
);