express-form-data
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/express-form-data package

2.0.23 • Public • Published

express-form-data

Module to parse multipart/form data. Based on connect-multiparty

Install

npm install express-form-data

Example

const formData = require("express-form-data");
const express = require("express");
const os = require("os");
const app = express();

/**
 * Options are the same as multiparty takes.
 * But there is a new option "autoClean" to clean all files in "uploadDir" folder after the response.
 * By default, it is "false".
 */
const options = {
  uploadDir: os.tmpdir(),
  autoClean: true
};

// parse data with connect-multiparty. 
app.use(formData.parse(options));
// delete from the request all empty files (size == 0)
app.use(formData.format());
// change the file objects to fs.ReadStream 
app.use(formData.stream());
// union the body and the files
app.use(formData.union());

After this we can see in req:

  • req.files = {...} all files
  • req.body = {...} all data including files (or streams if you use .stream())

Package Sidebar

Install

npm i express-form-data

Weekly Downloads

26,607

Version

2.0.23

License

MIT

Unpacked Size

8.91 kB

Total Files

6

Last publish

Collaborators

  • ortex