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.
Example
Section titled “Example”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,});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.
Properties
Section titled “Properties”accept
Section titled “accept”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
Section titled “bucket”bucket:
string
Defined in: packages/storage/src/types.ts:51
R2 binding name from the Workers environment (e.g. "UPLOADS").
hooks?
Section titled “hooks?”
optionalhooks: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.
Parameters
Section titled “Parameters”extension
Section titled “extension”string
string
KeyContext<TInput>
Returns
Section titled “Returns”string
maxSize
Section titled “maxSize”maxSize:
string
Defined in: packages/storage/src/types.ts:55
Maximum file size as a human-readable string (e.g. "10mb", "500kb").
multipartThreshold?
Section titled “multipartThreshold?”
optionalmultipartThreshold:string
Defined in: packages/storage/src/types.ts:63
File size above which multipart upload is used (default "5mb").
partSize?
Section titled “partSize?”
optionalpartSize:string
Defined in: packages/storage/src/types.ts:65
Size of each part in a multipart upload (default "10mb").
publicUrl?
Section titled “publicUrl?”
optionalpublicUrl:string
Defined in: packages/storage/src/types.ts:67
Base URL for publicly accessible files (used by getPublicUrl).
replace?
Section titled “replace?”
optionalreplace:boolean
Defined in: packages/storage/src/types.ts:59
When true, uploading replaces all existing files under the same key prefix.
uploadable?
Section titled “uploadable?”
optionaluploadable:boolean
Defined in: packages/storage/src/types.ts:61
When false, the file type cannot be uploaded directly (e.g. system-generated exports).