解决 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"
}));

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM