Multer is a node.js middleware for handling
multipart/form-data
for koa.
Alternative multer wrapper for koa v2's middleware using the async/await structure.
Uses Proxy instead of a plain function wrapper.
Tests are from koa-multer, but updated to modern node syntax.
$ npm install --save kuma-multer
const Koa = require('koa');
const Router = require('koa-router');
const Multer = require('kuma-multer');
const app = new Koa();
const router = new Router();
let upload = Multer({ dest: 'uploads/' });
router.post('/profile', upload.single('avatar'));
router.post('/profile/photos', upload.array('list'));
app.use(router.routes());
app.listen(3000);
Files are available via ctx.req.files
or ctx.request.files
.
If there is only one file, remove the plurality. (eg. ctx.req.file
)
Any text fields are available via ctx.req.body
or ctx.request.body
.