1

My Node.js web service will accept user uploads. I need to limit maximum number of bytes user can upload. I don't want to rely solely on content-length header since an invalid value can be provided. Is there a way I can limit request stream length I pipe to disk or db?

I thought about stream.Transform that will throw an exception if the stream length is longer than content-length header value. Probably, there is a built-in function?

Ivan Nikitin
  • 2,771
  • 22
  • 31
  • 1
    What middleware are you using to parse the uploads? Here are some options if you're using body-parser: [How to limit upload file size in Express](https://stackoverflow.com/questions/13374238/how-to-limit-upload-file-size-in-express-js) and if you're using multer [How to limit the file size when uploading with multer](https://stackoverflow.com/questions/34697502/how-to-limit-the-file-size-when-uploading-with-multer). – jfriend00 Mar 24 '20 at 15:27

0 Answers0