nodejs应用错误消息PayloadTooLarge的处理
生活随笔
收集整理的這篇文章主要介紹了
nodejs应用错误消息PayloadTooLarge的处理
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
今天使用nodejs開發(fā)時(shí),遇到如下錯(cuò)誤:
PayloadTooLargeError: request entity too large
根據(jù)出錯(cuò)信息顯示的node_modules\raw-body\index.js,進(jìn)入代碼:
在getRawBody方法里發(fā)現(xiàn)一個(gè)大小檢查邏輯,我傳入的json長(zhǎng)度為881790,而limit變量顯示為1024:
所以觸發(fā)了錯(cuò)誤檢查:
function readStream (stream, encoding, length, limit, callback) {var complete = falsevar sync = true// check the length and limit options.// note: we intentionally leave the stream paused,// so users should handle the stream themselves.if (limit !== null && length !== null && length > limit) {return done(createError(413, 'request entity too large', {expected: length,length: length,limit: limit,type: 'entity.too.large'}))}解決方案也很簡(jiǎn)單,添加一行代碼即可:
app.use(bodyParser.json({limit: ‘10mb’, extended: true}));
要獲取更多Jerry的原創(chuàng)文章,請(qǐng)關(guān)注公眾號(hào)"汪子熙":
總結(jié)
以上是生活随笔為你收集整理的nodejs应用错误消息PayloadTooLarge的处理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 女子吐槽领导隔监控点名员工加班 大家为工
- 下一篇: Jerry本地安装SAP Kyma的一些