Skip to content

filetype

filetype<TInput>(config): FiletypeConfig<TInput> & object

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

Define a file type with its constraints and key generation strategy.

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>

The file type configuration.

FiletypeConfig<TInput> & object

The config with defaults applied, fully resolved.

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