Network Processor Module

    @koa/multer
    DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/koa__multer package

    3.0.0 • Public • Published

    @koa/multer

    Route middleware for Koa that handles multipart/form-data using multer

    NPM version NPM Downloads Build status Test coverage Dependency status License

    Call for Maintainers

    This module is a fork of koa-multer, the most widely used multer middleware in the koa community. Due to lack of maintenance, it was forked to the official Koa organization and is available under @koa/multer package name.

    Install

    Note that you must install either multer@1.x (Buffer) or multer@2.x (Streams):

    npm install --save @koa/multer multer

    Usage

    const Koa = require('koa');
    const Router = require('@koa/router');
    const multer = require('@koa/multer');
    
    const app = new Koa();
    const router = new Router();
    const upload = multer(); // note you can pass `multer` options here
    
    // add a route for uploading multiple files
    router.post(
      '/upload-multiple-files',
      upload.fields([
        {
          name: 'avatar',
          maxCount: 1
        },
        {
          name: 'boop',
          maxCount: 2
        }
      ]),
      ctx => {
        console.log('ctx.request.files', ctx.request.files);
        console.log('ctx.files', ctx.files);
        console.log('ctx.request.body', ctx.request.body);
        ctx.body = 'done';
      }
    );
    
    // add a route for uploading single files
    router.post(
      '/upload-single-file',
      upload.single('avatar'),
      ctx => {
        console.log('ctx.request.file', ctx.request.file);
        console.log('ctx.file', ctx.file);
        console.log('ctx.request.body', ctx.request.body);
        ctx.body = 'done';
      }
    );
    
    // add the router to our app
    app.use(router.routes());
    app.use(router.allowedMethods());
    
    // start the server
    app.listen(3000);

    Contributors

    Name Website
    Nick Baugh http://niftylettuce.com/
    Imed Jaberi https://www.3imed-jaberi.com/

    License

    MIT © Fangdun Cai

    Install

    npm i @koa/multer

    DownloadsWeekly Downloads

    20,060

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    8.37 kB

    Total Files

    5

    Last publish

    Collaborators

    • titanism
    • niftylettuce
    • fengmk2
    • coderhaoxin
    • dead_horse
    • jongleberry
    • juliangruber
    • tjholowaychuk
    • aaron