multy
v0.1.5
Published
Koa(v2)/Express middleware for handle multipart form
Downloads
109
Maintainers
Readme
Installation
npm install multy
Usage
multy
will add all parts to req.body
or ctx.body
.
Parts is added in EXACTLY same order as received, important to mix of file and text in same form.
var Multy = require('multy')
app.use(Multy(options))
options
is same as busboy
Example
// on koa v2, works as well in express with req.body
const fs = require('fs')
const Multy = require('multy')
const app = new (require('koa'))()
const router = require('koa-Router')()
app.use(router)
router.use(Multy())
router.post('/', ctx => {
const { file } = ctx.request.body
const stream = fs.createWriteStream('potato.jpg')
ctx.body = 'potato'
return new Promise((resolve, reject) => {
file
.pipe(stream)
.on('close', _ => resolve())
.on('error', reject)
})
})
app.listen(3000)