Skip to content

FiletypeConfig

FiletypeConfig<TInput> = object

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

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:53

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


bucket: string

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

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


optional hooks: FiletypeHooks<TInput>

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

Lifecycle hooks that run before and after upload.


key: (file, ctx) => string

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

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:55

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


optional multipartThreshold: string

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

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


optional partSize: string

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

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


optional publicUrl: string

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

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


optional replace: boolean

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

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


optional uploadable: boolean

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

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