@fastify/multipart
Multipart form data / file upload plugin for Fastify — stream files directly to storage without buffering in memory.
@fastify/multipart
FastifyMultipart form data / file upload plugin for Fastify — stream files directly to storage without buffering in memory.
Fit
Bundle (gzip)
13.4 kB
39.8 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Fastify doesn't parse multipart/form-data requests by default. File uploads need streaming support to avoid loading large files entirely into memory before processing them.
What It Does
@fastify/multipart parses multipart requests and provides file data as readable streams or buffers. You can stream directly to S3 or the filesystem without buffering. It enforces file size limits, field count limits, and accepted MIME types.
Installation
npm install @fastify/multipartUsage Example
import fastify from 'fastify';
import multipart from '@fastify/multipart';
import { pipeline } from 'stream/promises';
import { createWriteStream } from 'fs';
const app = fastify();
await app.register(multipart, { limits: { fileSize: 10 * 1024 * 1024 } });
app.post('/upload', async (request, reply) => {
const data = await request.file();
const filename = `uploads/${Date.now()}-${data.filename}`;
await pipeline(data.file, createWriteStream(filename));
return { filename };
});Related packages
Auto-load Fastify plugins from a directory — organize routes and plugins as files and let the framework discover them automatically.
@fastify/cookieFastifyPlugin for Fastify that adds support for reading and setting cookies, including signed cookies.
@fastify/corsFastifyCORS plugin for Fastify — configure cross-origin resource sharing with full support for preflight requests and dynamic origins.
@fastify/helmetFastifySecurity headers plugin for Fastify — sets HTTP headers that protect against common web vulnerabilities like XSS, clickjacking, and MIME sniffing.
@fastify/jwtFastifyJWT authentication plugin for Fastify — sign, verify, and decode tokens with a decorator-based API that integrates with Fastify's request lifecycle.