Node.js - How do I limit the file upload size of a multipart form in formidable

2.7k views Asked by At

I know formidable has a form.maxFieldsSize, but that doesn't include files. How would I limit the maximum file size uploaded to a multipart form in formidable, and terminate the form if the file size is too large?

1

There are 1 answers

2
C.Unbay On BEST ANSWER

I think you can use the code down below for that kind of task.

var sizeLimitBytes = 2000;
form.on('progress', function(bytesReceived, bytesExpected) {
  if(bytesReceived > sizeLimitBytes ){
    return false; //exit the program
  }
});