https://github.com/koajs/bodyparser
https://www.npmjs.com/package/koa-bodyparser
413 Payload Too Large 
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status/413
响应状态码 413 Payload Too Large 表示请求主体的大小超过了服务器愿意或有能力处理的限度,
服务器可能会(may)关闭连接以防止客户端继续发送该请求
yarn add koa-bodyparser@2
413 Request Entiry Too large
post 提交数据的时,bodyparser 限制了大小问题?
request entity too large PayloadTooLargeError: request entity too large
status code:413 Request Entiry Too large
原因:
上传文件失败,报上面的错:请求实体太大
https://stackoverflow.com/questions/52783959/nest-js-request-entity-too-large-payloadtoolargeerror-request-entity-too-larg
midway
midway 使用的 bodyparser 是纯粹的 koa-bodyparser,支持配置,在 config/config.default.ts 中
exports.bodyParser = {formLimit: '5000kb',jsonLimit: '5000kb', // 设置为 5MB大小};
koa-bodyparse默认值
exports.bodyParser = {enableTypes: ['json', 'form', 'text', 'xml'],encoding: '',formLimit: '56kb', // 默认值jsonLimit: '1mb',textLimit: '1mb',xmlLimit: '1mb',strict: true,detectJSON: null}// detectJSONapp.use(bodyparser({detectJSON: function (ctx) {return /\.json$/i.test(ctx.path);}}));
- strict: true In strict mode, ctx.request.body will always be an object(or array), this avoid lots of type judging. But text body will always return string type.
 
express
express4.0之后的版本
const express = require('express');const bodyParser = require('body-parser');app.use(bodyParser.json({limit: '10mb'}));app.use(bodyParser.urlencoded({limit: '10mb', extended: true}));
express4.0之前的版本
app.use(express.json({limit: '10mb'}));app.use(express.urlencoded({limit: '10mb'}));
https://gist.github.com/Maqsim/857a14a4909607be13d6810540d1b04f
https://stackoverflow.com/questions/19917401/error-request-entity-too-large
nest.js
import * as bodyParser from 'body-parser';import { AppModule } from './app.module';async function bootstrap() {const app = await NestFactory.create(AppModule);app.useStaticAssets(`${__dirname}/public`);// the next two lines did the trickapp.use(bodyParser.json({limit: '50mb'}));app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));app.enableCors();await app.listen(3001);}bootstrap();
nginx修改
nginx有个参数client_max_body_size在限制请求实体的大小,把它改大点就好了。
{如果配置文件没有这个参数,应该会在系统里有个默认的值}
- 打开nginx配置文件 nginx.conf, 路径一般是:/etc/nginx/nginx.conf。
 - 在http{}段中加入 client_max_body_size 20m。20m为允许上传的最大值,可自己决定多大。
 - 保存后重启nginx
 
vi /etc/nginx/nginx.confsudo nano /etc/nginx/nginx.confvi /usr/local/nginx/conf/nginx.conf# set client body size to 2M #client_max_body_size 2M;
https://www.cyberciti.biz/faq/linux-unix-bsd-nginx-413-request-entity-too-large/
