koay-body

1.0.0 • Public • Published

koay-body

npm package

Note: A full-featured koa body parser middleware. Supports multipart, urlencoded, and json request bodies.


Installation

Node >= 7.6

npm install --save koay-body

Usage

const bodyParser = require('koay-body');
const Koa = require('koa');
 
const app = new Koa();
 
app.use(bodyParser({
  formidable: {}, // default
  requestBody: 'body', // default
  requestFiles: 'files' // default
}));
app.use((ctx) => {
  // 禁用bodyparser
  ctx.disableBodyParser = true;
});
app.use((ctx) => {
  const { body } = ctx.request;
 
  console.log(body);
  
  ctx.body = body;
});

Options explanation:

  • encoding 设置表单字段的编码
  • uploadDir 设置上传后的文件存放的目录, 默认为: os.tmpdir()
  • keepExtensions 设置上传后的文件是否保持原来的扩展名
  • type 可以设置成 multipart or urlencoded
  • maxFieldsSize 设置提交到后台数据的大小, 默认为: 20MB
  • maxFileSize 设置上传文件的大小, 默认为: 200MB
  • maxFields 设置url后面可接收的参数, 默认为: 1000
  • hash 使用sha1 or md5校验文件

Go to formidable API

Dependencies (3)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i koay-body

    Weekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    4.74 kB

    Total Files

    4

    Last publish

    Collaborators

    • fengxinming