如何让 node.js 主体解析器抱怨负载太大

how to get node.js body-parser complaining about payload being too large

所以我有一条 post 路线,有效负载是 json。

它有很多字段,一个是base64编码的字符串,对应一个大的png文件。

我得到的错误是

PayloadTooLargeError: request entity too large
    at readStream (/Users/reza.razavipour/Projects/s3uploader/node_modules/raw-body/index.js:155:17)
    at getRawBody (/Users/reza.razavipour/Projects/s3uploader/node_modules/raw-body/index.js:108:12)
    at read (/Users/reza.razavipour/Projects/s3uploader/node_modules/body-parser/lib/read.js:77:3)

如何绕过此限制?

将来我将不得不处理非常大的 Gbs zip 文件...

According to documentation 有一个 limit 选项可以传递给 json 解析器以配置正文限制。

limit

Controls the maximum request body size. If this is a number, then the value specifies the number of bytes; if it is a string, the value is passed to the bytes library for parsing. Defaults to '100kb'.

100 兆字节的类似内容:

bodyParser.json({ limit: '100mb' })