Plugins
File Upload
Type-safe file upload handling — validate size, MIME type, and access files in procedures.
Parse multipart file uploads with size and MIME type validation. Files are available in the procedure context.
Usage
import { } from "katman/plugins"
const = k.mutation({
: [({
: 5 * 1024 * 1024, // 5 MB
: ["image/*"],
})],
: async ({ }) => {
const = .file
const = await .arrayBuffer()
return { : .name, : .size, : .type }
},
})Options
| Option | Type | Default | Description |
|---|---|---|---|
maxFileSize | number | 10485760 (10 MB) | Maximum file size in bytes |
allowedTypes | string[] | all | Allowed MIME types (supports image/* wildcards) |
maxFiles | number | 1 | Maximum number of files |
fieldName | string | "file" | Form field name |
Multiple files
Set maxFiles to allow multiple uploads. Files are available as ctx.files:
const = k.mutation({
: [fileGuard({ : 10, : ["image/*"] })],
: async ({ }) => {
return .files.map( => ({ : .name, : .size }))
},
})Manual parsing
For custom file handling, use parseMultipart() directly:
import { } from "katman/plugins"
const = k.mutation({
: async ({ }) => {
const { , } = await (.__request)
return { : ., : . }
},
})The file guard validates before the procedure runs. If a file exceeds the size limit or has a disallowed MIME type, the request is rejected with 400 or 413 immediately.
What's next?
- Body Limit — limit total request body size
- Plugins — other available plugins