Katman
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

OptionTypeDefaultDescription
maxFileSizenumber10485760 (10 MB)Maximum file size in bytes
allowedTypesstring[]allAllowed MIME types (supports image/* wildcards)
maxFilesnumber1Maximum number of files
fieldNamestring"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?

On this page