1.1.0 • Published 9 years ago
koa-formidable v1.1.0
koa-formidable
Formidable middleware for Koa
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 ofIncomingFormdirectly)
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 ofIncomingFormdirectly) - 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)