API Reference

Multer

Express middleware for multipart/form-data uploads with disk or memory storage, field limits, file filters, and multiple file handling.

Official Documentation ↗
CompatibilityThis documentation covers version v2.5.0. Check the official docs for the latest API surface.

Installation

npmnpm install multer
pnpmpnpm add multer
yarnyarn add multer

Methods

Multer parses multipart/form-data and exposes files to Express. It is a parser, not a complete upload security layer. Configure a storage destination, size and count limits, and a filter, then validate the file content and generate a safe storage name on the server.

Storage and limits

Disk storage writes files to the filesystem; memory storage buffers them in RAM and should only be used for small files. Set fileSize and files limits before the parser reads the whole body. The reverse proxy and application should enforce compatible limits so a large request is rejected at the edge.

Validate after upload

The client-provided filename and MIME type are untrusted. Generate a new name, validate the extension, inspect the file signature, and store uploads outside the web root or in object storage. Serve user files with a restrictive content type and disposition.

Errors

The following points are quoted verbatim from the official documentation (https://expressjs.com/en/resources/middleware/multer.html). Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

Security notes

Quoted from the official documentation (https://expressjs.com/en/resources/middleware/multer.html); this is not a complete threat model.

FAQ

Does Multer limit upload size by default?
No. The default fileSize and file count limits are not a complete protection. Set explicit limits and enforce the same or a stricter limit in the application and reverse proxy.
Is the mimetype reported by Multer trustworthy?
No. It comes from the client. Use it only as an early filter, then inspect the saved file's signature and run malware scanning if uploads are public.
Can I use the original filename for storage?
Avoid it. The name can contain traversal sequences or conflicting characters. Generate a UUID or hash, store the original name as metadata, and validate the extension.