1. 程式人生 > 實用技巧 >解決 koa request entity too large

解決 koa request entity too large

POST資料太大,出現了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" }));