Skip to content

FiletypeConfig

FiletypeConfig<TInput> = object

Defined in: packages/storage/src/types.ts:136

Configuration for a single file type within a storage schema.

Defines the R2 bucket, accepted MIME types, size limits, key generation strategy, and optional lifecycle hooks for a category of files.

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

TInput = Record<string, unknown>

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

accept: readonly string[]

Defined in: packages/storage/src/types.ts:140

MIME types accepted for this file type (e.g. ["image/jpeg", "image/png"]).


bucket: string

Defined in: packages/storage/src/types.ts:138

R2 binding name from the Workers environment (e.g. "UPLOADS").


optional hooks: FiletypeHooks<TInput>

Defined in: packages/storage/src/types.ts:156

Lifecycle hooks that run before and after upload.


key: (file, ctx) => string

Defined in: packages/storage/src/types.ts:144

Function that generates the R2 object key for an uploaded file.

string

string

KeyContext<TInput>

string


maxSize: string

Defined in: packages/storage/src/types.ts:142

Maximum file size as a human-readable string (e.g. "10mb", "500kb").


optional mimeGroups: readonly NormalizedMimeGroup[]

Defined in: packages/storage/src/types.ts:164

Optional per-mime-group size limits. When set, each mime group’s maxSize is enforced independently — a file whose mime type belongs to a given group must fit within that group’s limit.

Populated automatically when using the per-mime form of filetype.


optional multipartThreshold: string

Defined in: packages/storage/src/types.ts:150

File size above which multipart upload is used (default "5mb").


optional ownerCheck: OwnerCheck

Defined in: packages/storage/src/types.ts:169

Optional access-control gate evaluated by the /uploads/* proxy route before streaming a private R2 object. See OwnerCheck.


optional partSize: string

Defined in: packages/storage/src/types.ts:152

Size of each part in a multipart upload (default "10mb").


optional publicUrl: string

Defined in: packages/storage/src/types.ts:154

Base URL for publicly accessible files (used by getPublicUrl).


optional replace: boolean

Defined in: packages/storage/src/types.ts:146

When true, uploading replaces all existing files under the same key prefix.


optional uploadable: boolean

Defined in: packages/storage/src/types.ts:148

When false, the file type cannot be uploaded directly (e.g. system-generated exports).