Volt v0.1 · TypeScript APIs on Bun · Get started
Docs/Guides/File Uploads

File Uploads

Receive multipart files with explicit size checks.

Complete upload example

index.ts
import { Volt } from 'voltts';

const app = new Volt({ maxRequestBodySize: 2 * 1024 * 1024 });
app.post('/upload', async (c) => {
  const file = await c.file('document');
  if (!file) return c.json({ error: 'document is required' }, 400);
  if (file.size > 1024 * 1024) {
    return c.json({ error: 'File must be at most 1 MiB' }, 413);
  }
  return c.json({ name: file.name, size: file.size, type: file.type }, 201);
});
if (globalThis._importMeta_.main) app.listen(3000);
export default app;

Send a file

bash
bun run index.ts
printf 'Hello Volt' > sample.txt
curl -i -X POST http://localhost:3000/upload -F '[email protected]'

Expect 201 with the file name, size, and MIME type. c.files('document') reads repeated files; c.formData() exposes the parsed FormData.

Handling uploaded data

This example returns metadata only. Validate file size and content before persisting anything. A client's MIME type and file name are untrusted. Generate a storage key rather than using the uploaded name as a path. Bun's server enforces maxRequestBodySize on real network requests; in-memory tests do not replace network-level limit checks.