Node.js: how to limit the HTTP request size and upload file size?

后端 未结 7 1688
轮回少年
轮回少年 2020-12-08 20:35

I\'m using Node.js and express.

I would like to limit the HTTP request size. Let\'s say, if someone sends me a HTTP request more than 2 MB then I stop the request r

7条回答
  •  一个人的身影
    2020-12-08 21:05

    Just an update (07-2014), as I'm not able to add comments:

    As correctly noted above, newer Express versions have deprecated the use of the limit middleware and now provide it as a built-in option for the BodyParser middleware:

       var express    = require('express')
       var bodyParser = require('body-parser')
    
       var app = express()
       app.use(bodyParser.json({ limit: '5mb' }))
    

提交回复
热议问题