Skip to content

Commit

Permalink
Added MaxFileSize to IncomingForm options
Browse files Browse the repository at this point in the history
  • Loading branch information
stueynz committed Oct 30, 2016
1 parent d93055d commit f6b7005
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion lib/incoming_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function IncomingForm(opts) {

this.maxFields = opts.maxFields || 1000;
this.maxFieldsSize = opts.maxFieldsSize || 2 * 1024 * 1024;
this.maxFileSize = opts.maxFileSize || 2 * 1024 * 1024;
this.keepExtensions = opts.keepExtensions || false;
this.uploadDir = opts.uploadDir || os.tmpDir();
this.encoding = opts.encoding || 'utf-8';
Expand Down Expand Up @@ -217,6 +218,13 @@ IncomingForm.prototype.handlePart = function(part) {
if (buffer.length == 0) {
return;
}
// compare receivedBytes with maxFileSize
if((file.toJSON().size + buffer.length) > self.maxFileSize) {
self._error(new Error('Size overflow, expect ' + self.maxFileSize +
' but received ' + (file.toJSON().size + buffer.length) + ' bytes'));
return;
}

self.pause();
file.write(buffer, function() {
self.resume();
Expand Down Expand Up @@ -555,4 +563,3 @@ IncomingForm.prototype._maybeEnd = function() {

this.emit('end');
};

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "formidable",
"description": "A node.js module for parsing form data, especially file uploads.",
"homepage": "https://github.com/felixge/node-formidable",
"version": "1.0.17",
"version": "1.0.17-stu",
"devDependencies": {
"gently": "0.8.0",
"findit": "0.1.1",
Expand All @@ -24,10 +24,10 @@
},
"repository": {
"type": "git",
"url": "git://github.com/felixge/node-formidable.git"
"url": "git://github.com/stueynz/node-formidable.git"
},
"bugs": {
"url": "http://github.com/felixge/node-formidable/issues"
"url": "http://github.com/stueynz/node-formidable/issues"
},
"optionalDependencies": {}
}

0 comments on commit f6b7005

Please sign in to comment.