koa-formidable

1.1.0 • Public • Published

koa-formidable

Formidable middleware for Koa

![NPM][npm] ![Dependency Status][dependencies]

Breaking Change in 1.0.0: both body and files are now added to Koa's .request instead of modifying the http request (.req) directly.

API

var formidable = require('koa-formidable')

formidable(opts)

Returns the formidable middleware that parses the incoming request and adds the .request.body and .request.files to the context.

Arguments:

  • opts - the options that get passed to the Formidable.IncomingForm (you could also provide an instance of IncomingForm directly)

Example:

var formidable = require('koa-formidable')
app.use(formidable())

formidable.parse(opts, ctx)

Parse the incoming request manually.

Arguments:

  • opts - the options that get passed to the Formidable.IncomingForm (you could also provide an instance of IncomingForm directly)
  • ctx - the Koa context

Example:

var formidable = require('koa-formidable')
app.use(function*(next) {
  var form = yield formidable.parse(this)
  ...
  yield next
})

Using formidable Events

Example:

var form = new require('formidable').IncomingForm()
form.on('progress', function(bytesReceived, bytesExpected) {
      console.log(bytesReceived, bytesExpected)
})
var result = yield formidable.parse(form, this)

License

MIT

Package Sidebar

Install

npm i koa-formidable

Weekly Downloads

387

Version

1.1.0

License

none

Last publish

Collaborators

  • rkusa