Skip to content

EduardoRFS/multy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Koa/Express multipart handler

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published