kyk's blog

Expressjs Multer File Upload

Expressjs + Multer for file upload.

Usages:

multer({ limits, fileFilter, storage }) creates Multer object for reusable in different requset handlers.

  • limits limit fileSize, fieldName, etc…
  • fileFilter custom file validation
  • storage disk / memory / custom storage transform ([s3)

multer().array('photos', 2) creates request handler for different routes.

  • single one file upload, get by req.file
  • array multiple files upload, get by req.files
  • fields multiple field for files upload, get by req.files[<fieldName>][0]

Example