import type { Plugin } from './app'; /** * One uploaded file from a `multipart/form-data` body. Wraps the web `File` * with the originating field name and convenience readers; `size`/`type` are * available without reading the contents. */ export declare class UploadedFile { /** The form field this file arrived under. */ readonly field: string; private readonly file; constructor( /** The form field this file arrived under. */ field: string, file: File); /** The client-supplied filename — untrusted; sanitize before using it as a filesystem path. May be empty. */ get filename(): string; /** The client-declared MIME type (the part's `Content-Type`), not sniffed from the bytes — treat it as a hint, not a guarantee. */ get type(): string; /** Size in bytes. */ get size(): number; /** The underlying web `File` (for streaming or passing through). */ get blob(): File; /** * Read the entire file into memory as bytes. The upload is already fully in * memory (the whole body was buffered by `req.formData()` during parsing), so * this only copies it into a `Uint8Array`; use {@link UploadedFile.blob} to * pass the `File` through without the extra copy. * * @returns the full contents as a `Uint8Array` */ bytes(): Promise; /** * Read the entire file into memory and decode it as UTF-8 text. * * @returns the file's contents decoded as a string */ text(): Promise; } /** The parsed shape of a `multipart/form-data` body (via `ctx.body()`). */ export interface MultipartBody { /** Non-file form fields. Repeated names keep the last value. */ fields: Record; /** Uploaded files grouped by field name. */ files: Record; } /** Options for {@link multipart}. */ export interface MultipartOptions { /** Reject once more than this many files arrive (`400`). */ maxFiles?: number; /** Reject any single file larger than this many bytes (`413`). */ maxFileSize?: number; /** Reject once the combined file size exceeds this many bytes (`413`). */ maxTotalSize?: number; /** * Allowed MIME types (`415` otherwise). Exact (`"image/png"`) or a subtype * wildcard (`"image/*"`). */ allowedTypes?: string[]; } /** * Plugin: parse `multipart/form-data` bodies into `{ fields, files }`, readable * through `ctx.body()` like any other body. `req.formData()` * first buffers the entire request body into memory; the optional * count/size/type limits then reject violations with `400`/`413`/`415` but do * not cap what is read into memory — that ceiling is Bun's `maxRequestBodySize`. * * ```ts * const app = await createApp({ * plugins: [multipart({ maxFileSize: 5_000_000, allowedTypes: ['image/*'] })], * }) * // in a handler: const { fields, files } = await ctx.body() * ``` * * @param options - optional count/size/type upload limits * @returns a plugin registering a `multipart/form-data` body parser */ export declare function multipart(options?: MultipartOptions): Plugin; //# sourceMappingURL=multipart.d.ts.map