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 'silgi/plugins'
const = k
.$use(
({
: 5 * 1024 * 1024, // 5 MB
: ['image/*'],
}),
)
.$resolve(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 = s.$use(fileGuard({ : 10, : ['image/*'] })).$resolve(async ({ }) => {
return .files.map(() => ({ : .name, : .size }))
})Manual parsing
For custom file handling, use parseMultipart() directly:
import { } from 'silgi/plugins'
const = s.$resolve(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