koa-busboy
A koa's middleware for handling multipart form.
Note that, this middleware supports Koa v2
only.
Installation
$ npm i -S koa-busboy
Usage
koa-busboy
will adds all text fields
to ctx.request.body
object and uploaded files
to ctx.request.files
array.
To create middleware, simply call the module function with custom config options as following:
const busboy = const uploader =
While, options
is same as original busboy module.
However, you can specify the following options also.
-
dest - string - The folder to save uploaded files (Default: system temp folder -
os.tmpdir()
). -
fnDestFilename - function - The function that defines the final filename which saved on
dest
folder. ThefnDestFilename(fieldname, filename)
function will return the name of file which be saved on disk. Whilefieldname
is your uploaded field's name andfilename
is your uploaded file's name. (Default:(fieldname, filename) => Date.now() + fieldname + filename
)
Example
const busboy = const koaRouter = const uploader = const router = router