express-formidable

An Express middleware of Formidable that just works.

express-formidable downloads express-formidable version express-formidable license

express-formidable類似套件:

npm下載趨勢

3 年
🌟 在 express-formidable 的 README.md 中顯示即時使用量圖表,只需複製下面的代碼。
## Usage Trend
[![Usage Trend of express-formidable](https://npm-compare.com/img/npm-trend/THREE_YEARS/express-formidable.png)](https://npm-compare.com/express-formidable#timeRange=THREE_YEARS)

Cumulative GitHub Star Trend

🌟 在 express-formidable 的 README.md 中顯示 GitHub stars 趨勢圖表,只需複製下面的代碼。
## GitHub Stars Trend
[![GitHub Stars Trend of express-formidable](https://npm-compare.com/img/github-trend/express-formidable.png)](https://npm-compare.com/express-formidable)

統計詳情

套件
下載數
Stars
大小
Issues
發布時間
許可
express-formidable96,743127-248 年前MIT

express-formidable 的 README

express-formidable Build Status

An Express middleware of Formidable that just works.

What are Express, Formidable, and this?

Express is a fast, unopinionated, minimalist web framework for Node.js.

Formidable is a Node.js module for parsing form data, including multipart/form-data file upload.

So, express-formidable is something like a bridge between them, specifically an Express middleware implementation of Formidable.

It aims to just work.

Install

npm install express-formidable

How to use

const express = require('express');
const formidableMiddleware = require('express-formidable');

var app = express();

app.use(formidableMiddleware());

app.post('/upload', (req, res) => {
  req.fields; // contains non-file fields
  req.files; // contains files
});

And that's it.

express-formidable can basically parse form types Formidable can handle, including application/x-www-form-urlencoded, application/json, and multipart/form-data.

Option

app.use(formidableMiddleware(opts));

opts are options which can be set to form in Formidable. For example:

app.use(formidableMiddleware({
  encoding: 'utf-8',
  uploadDir: '/my/dir',
  multiples: true, // req.files to be arrays of files
});

For the detail, please refer to the Formidable API.

Events

app.use(formidableMiddleware(opts, events));

events is an array of json with two field:

FieldDescription
eventThe event emitted by the form of formidable. A complete list of all the possible events, please refer to the Formidable Events
actionThe callback to execute. The signature is function (req, res, next, ...formidable_parameters)

For example:

const events = [
  {
    event: 'fileBegin',
    action: function (req, res, next, name, file) { /* your callback */ }
  }, 
  {
    event: 'field',
    action: function (req, res, next, name, value) { /* your callback */ }
  }
];

Error event

Unless an error event are provided by the events array parameter, it will handle by the standard next(error).

Contribute

git clone https://github.com/noraesae/express-formidable.git
cd express-formidable
npm install

To lint and test:

npm test

License

MIT