解决 koa request entity too large

POST数据太大,出现了413错误,错误描述 request entity too large

原因:

使用了koa-body,koa-bodyparser,从它们的README看,接收的参数有默认大小

koa-body

- `jsonLimit` **{String|Integer}** The byte (if integer) limit of the JSON body, default `1mb`
- `formLimit` **{String|Integer}** The byte (if integer) limit of the form body, default `56kb`
- `textLimit` **{String|Integer}** The byte (if integer) limit of the text body, default `56kb`

koa-bodyparser

* **formLimit**: limit of the `urlencoded` body. If the body ends up being larger than this limit, a 413 error code is returned. Default is `56kb`.
* **jsonLimit**: limit of the `json` body. Default is `1mb`.
* **textLimit**: limit of the `text` body. Default is `1mb`.

解决的方法

const koaBody = require('koa-body');
const bodyParser = require('koa-bodyparser')

app.use(koaBody({
    multipart: true,
    formLimit:"10mb",
    jsonLimit:"10mb"
}));
app.use(bodyParser({
    formLimit:"10mb",
    jsonLimit:"10mb"
}));
原文地址:https://www.cnblogs.com/baby123/p/13359472.html