Search code examples
node.jsuploadexpress

How to limit upload file size in express.js


i got this error says

error:request entity too large 

when uploading a video about 30MB,

here is the setting code

app.use(express.bodyParser({
    uploadDir:'./Temp',
    maxFieldsSize:'2 * 1024 * 1024 * 1024 ',
}));

am not sure how to set the maxFieldsSize property, need some help!!!


Solution

  • Express uses connect middleware, you can specify the file upload size by using the following

    app.use(express.limit('4M'));
    

    Connect Limit middleware