when to check for file size/mimetype in node.js upload script?

前端 未结 2 995
借酒劲吻你
借酒劲吻你 2021-01-13 12:08

I created an upload script in node.js using express/formidable. It basically works, but I am wondering where and when to check the uploaded file e. g. for the maximum file s

2条回答
  •  心在旅途
    2021-01-13 12:29

    The new version of Connect (2.x.) has this already baked into the bodyParser using the limit middleware: https://github.com/senchalabs/connect/blob/master/lib/middleware/multipart.js#L44-61

    I think it's much better this way as you just kill the request when it exceeds the maximum limit instead of just stopping the formidable parser (and letting the request "go on").

    More about the limit middleware: http://www.senchalabs.org/connect/limit.html

提交回复
热议问题