From d3d73b2847cbc104f29322e952b3fe32dac2d08b Mon Sep 17 00:00:00 2001 From: "alessio.montagnani" Date: Fri, 18 Apr 2014 12:59:09 +0200 Subject: [PATCH 01/29] Now the JSON Parser emit an error event to the IncomingForm if a receive a malformed JSON request. This way I can catch the error from my framework. --- lib/incoming_form.js | 2 +- lib/json_parser.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/incoming_form.js b/lib/incoming_form.js index 27b9aedb..4f4a8e57 100644 --- a/lib/incoming_form.js +++ b/lib/incoming_form.js @@ -508,7 +508,7 @@ IncomingForm.prototype._initOctetStream = function() { IncomingForm.prototype._initJSONencoded = function() { this.type = 'json'; - var parser = new JSONParser() + var parser = new JSONParser(this) , self = this; if (this.bytesExpected) { diff --git a/lib/json_parser.js b/lib/json_parser.js index db39c310..24ef63b1 100644 --- a/lib/json_parser.js +++ b/lib/json_parser.js @@ -2,7 +2,8 @@ if (global.GENTLY) require = GENTLY.hijack(require); var Buffer = require('buffer').Buffer; -function JSONParser() { +function JSONParser(parent) { + this.parent = parent; this.data = new Buffer(''); this.bytesWritten = 0; } @@ -28,7 +29,9 @@ JSONParser.prototype.end = function() { for (var field in fields) { this.onField(field, fields[field]); } - } catch (e) {} + } catch (e) { + this.parent.emit('error', e); + } this.data = null; this.onEnd(); From 35166edda691c9eac27328be54cd2b6b6613cd76 Mon Sep 17 00:00:00 2001 From: Nick Stamas Date: Wed, 10 Dec 2014 09:19:58 -0500 Subject: [PATCH 02/29] add hash to json if present --- lib/file.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/file.js b/lib/file.js index e34c10e4..d9ddf820 100644 --- a/lib/file.js +++ b/lib/file.js @@ -35,7 +35,7 @@ File.prototype.open = function() { }; File.prototype.toJSON = function() { - return { + json = { size: this.size, path: this.path, name: this.name, @@ -45,6 +45,10 @@ File.prototype.toJSON = function() { filename: this.filename, mime: this.mime }; + if (this.hash && this.hash != "") { + json.hash = this.hash; + } + return json; }; File.prototype.write = function(buffer, cb) { From 0864eaf2d23d589fb70f51889d7b07df54742c65 Mon Sep 17 00:00:00 2001 From: Nick Stamas Date: Mon, 15 Dec 2014 08:58:21 -0500 Subject: [PATCH 03/29] fix global variable leak --- lib/file.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/file.js b/lib/file.js index d9ddf820..01f3a895 100644 --- a/lib/file.js +++ b/lib/file.js @@ -35,7 +35,7 @@ File.prototype.open = function() { }; File.prototype.toJSON = function() { - json = { + var json = { size: this.size, path: this.path, name: this.name, From a884d6bd3ce07c3d61ce0d07fa66ab947f437b2e Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Sat, 18 Apr 2015 08:34:22 -0700 Subject: [PATCH 04/29] Use built-in toString to convert buffer to hex --- lib/incoming_form.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/incoming_form.js b/lib/incoming_form.js index b4234456..a13d72e9 100644 --- a/lib/incoming_form.js +++ b/lib/incoming_form.js @@ -529,11 +529,8 @@ IncomingForm.prototype._initJSONencoded = function() { }; IncomingForm.prototype._uploadPath = function(filename) { - var name = 'upload_'; var buf = crypto.randomBytes(16); - for (var i = 0; i < buf.length; ++i) { - name += ('0' + buf[i].toString(16)).slice(-2); - } + var name = 'upload_' + buf.toString('hex'); if (this.keepExtensions) { var ext = path.extname(filename); From 32c10fc1270d604dfae1e28b62ba797656e0d661 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 15 May 2015 14:21:54 +0200 Subject: [PATCH 05/29] Add license to package.json --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ec587e2..d0d2ac75 100644 --- a/package.json +++ b/package.json @@ -29,5 +29,6 @@ "bugs": { "url": "http://github.com/felixge/node-formidable/issues" }, - "optionalDependencies": {} + "optionalDependencies": {}, + "license": "MIT" } From e5491cbff584d6b7a3bacbd23d06d02cc5f916f9 Mon Sep 17 00:00:00 2001 From: Jonas Amundsen Date: Sat, 25 Jun 2016 00:50:20 +0200 Subject: [PATCH 06/29] Access WriteStream of fs during runtime instead of include time This adds compatibility with mock-fs [1], which overrides these methods and expects modules to access them thereafter. [1] https://github.com/tschaub/mock-fs --- lib/file.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/file.js b/lib/file.js index e34c10e4..5032de08 100644 --- a/lib/file.js +++ b/lib/file.js @@ -1,7 +1,7 @@ if (global.GENTLY) require = GENTLY.hijack(require); var util = require('util'), - WriteStream = require('fs').WriteStream, + fs = require('fs'), EventEmitter = require('events').EventEmitter, crypto = require('crypto'); @@ -31,7 +31,7 @@ module.exports = File; util.inherits(File, EventEmitter); File.prototype.open = function() { - this._writeStream = new WriteStream(this.path); + this._writeStream = new fs.WriteStream(this.path); }; File.prototype.toJSON = function() { From 81254a8f804e78088027877a87e78d2a5abb6b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Fri, 18 Nov 2016 19:10:45 +0000 Subject: [PATCH 07/29] Update buffer.write order of arguments --- test/legacy/integration/test-multipart-parser.js | 2 +- test/legacy/simple/test-multipart-parser.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/legacy/integration/test-multipart-parser.js b/test/legacy/integration/test-multipart-parser.js index 2ddea476..45047fef 100644 --- a/test/legacy/integration/test-multipart-parser.js +++ b/test/legacy/integration/test-multipart-parser.js @@ -50,7 +50,7 @@ Object.keys(fixtures).forEach(function(name) { endCalled = true; }; - buffer.write(fixture.raw, 'binary', 0); + buffer.write(fixture.raw, 0, undefined, 'binary'); while (offset < buffer.length) { if (offset + CHUNK_LENGTH < buffer.length) { diff --git a/test/legacy/simple/test-multipart-parser.js b/test/legacy/simple/test-multipart-parser.js index bf2cd5e1..c732d32f 100644 --- a/test/legacy/simple/test-multipart-parser.js +++ b/test/legacy/simple/test-multipart-parser.js @@ -34,7 +34,7 @@ test(function parserError() { buffer = new Buffer(5); parser.initWithBoundary(boundary); - buffer.write('--ad', 'ascii', 0); + buffer.write('--ad', 0); assert.equal(parser.write(buffer), 5); }); From 321e922b45cb368c25de32e2a3b0d7270dbdf87e Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 7 Dec 2016 22:08:39 +0100 Subject: [PATCH 08/29] Fix first DeprecationWarning about os.tmpDir() --- lib/incoming_form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/incoming_form.js b/lib/incoming_form.js index e3c8019a..c12ece9b 100644 --- a/lib/incoming_form.js +++ b/lib/incoming_form.js @@ -26,7 +26,7 @@ function IncomingForm(opts) { this.maxFields = opts.maxFields || 1000; this.maxFieldsSize = opts.maxFieldsSize || 2 * 1024 * 1024; this.keepExtensions = opts.keepExtensions || false; - this.uploadDir = opts.uploadDir || os.tmpDir(); + this.uploadDir = opts.uploadDir || (os.tmpdir && os.tmpdir()) || os.tmpDir(); this.encoding = opts.encoding || 'utf-8'; this.headers = null; this.type = null; From 63b4e9d73b7d9265404c0c5fa0a92c28efb6c717 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 7 Dec 2016 22:10:42 +0100 Subject: [PATCH 09/29] Fix second DeprecationWarning about os.tmpDir() --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 7aaee33a..7847237e 100644 --- a/Readme.md +++ b/Readme.md @@ -87,7 +87,7 @@ Sets encoding for incoming form fields. form.uploadDir = "/my/dir"; ``` Sets the directory for placing file uploads in. You can move them later on using -`fs.rename()`. The default is `os.tmpDir()`. +`fs.rename()`. The default is `os.tmpdir()`. ```javascript form.keepExtensions = false; @@ -304,7 +304,7 @@ Emitted when the entire request has been received, and all contained files have * Remove support for Node.js 0.4 & 0.6 (Andrew Kelley) * Documentation improvements (Sven Lito, Andre Azevedo) * Add support for application/octet-stream (Ion Lupascu, Chris Scribner) -* Use os.tmpDir() to get tmp directory (Andrew Kelley) +* Use os.tmpdir() to get tmp directory (Andrew Kelley) * Improve package.json (Andrew Kelley, Sven Lito) * Fix benchmark script (Andrew Kelley) * Fix scope issue in incoming_forms (Sven Lito) From 1cece1d46a542e4d76339d15d3a11aa757635097 Mon Sep 17 00:00:00 2001 From: Nicholai Nissen Date: Thu, 8 Dec 2016 16:31:29 +0100 Subject: [PATCH 10/29] Include MIT license --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 4ec587e2..74145a6a 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "formidable", "description": "A node.js module for parsing form data, especially file uploads.", "homepage": "https://github.com/felixge/node-formidable", + "license": "MIT", "version": "1.0.17", "devDependencies": { "gently": "0.8.0", From 9f975c6d344998d894b30c7dea2ed871601652d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Fri, 18 Nov 2016 19:10:45 +0000 Subject: [PATCH 11/29] Update buffer.write order of arguments --- test/legacy/integration/test-multipart-parser.js | 2 +- test/legacy/simple/test-multipart-parser.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/legacy/integration/test-multipart-parser.js b/test/legacy/integration/test-multipart-parser.js index 2ddea476..45047fef 100644 --- a/test/legacy/integration/test-multipart-parser.js +++ b/test/legacy/integration/test-multipart-parser.js @@ -50,7 +50,7 @@ Object.keys(fixtures).forEach(function(name) { endCalled = true; }; - buffer.write(fixture.raw, 'binary', 0); + buffer.write(fixture.raw, 0, undefined, 'binary'); while (offset < buffer.length) { if (offset + CHUNK_LENGTH < buffer.length) { diff --git a/test/legacy/simple/test-multipart-parser.js b/test/legacy/simple/test-multipart-parser.js index bf2cd5e1..c732d32f 100644 --- a/test/legacy/simple/test-multipart-parser.js +++ b/test/legacy/simple/test-multipart-parser.js @@ -34,7 +34,7 @@ test(function parserError() { buffer = new Buffer(5); parser.initWithBoundary(boundary); - buffer.write('--ad', 'ascii', 0); + buffer.write('--ad', 0); assert.equal(parser.write(buffer), 5); }); From 910fdcb1fce5eede5866dbbeb6cda976c015b4e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Tue, 13 Dec 2016 00:36:09 +0000 Subject: [PATCH 12/29] Test on current Node versions --- .travis.yml | 6 +++--- Readme.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e20bedc3..694a62f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js node_js: - - 0.8 - - "0.10" - - 0.11 + - 4 + - 6 + - 7 diff --git a/Readme.md b/Readme.md index 7847237e..6f5d410b 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,6 @@ # Formidable -[![Build Status](https://secure.travis-ci.org/felixge/node-formidable.png?branch=master)](http://travis-ci.org/felixge/node-formidable) +[![Build Status](https://secure.travis-ci.org/pornel/node-formidable.png?branch=master)](http://travis-ci.org/pornel/node-formidable) ## Purpose From 09833170fda6b73085421356f341a93053ad24d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Wed, 11 Jan 2017 16:02:10 +0100 Subject: [PATCH 13/29] Update current status --- Readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Readme.md b/Readme.md index 7aaee33a..8e8840b8 100644 --- a/Readme.md +++ b/Readme.md @@ -8,6 +8,8 @@ A node.js module for parsing form data, especially file uploads. ## Current status +**Maintainer Wanted:** Please see https://github.com/felixge/node-formidable/issues/412 + This module was developed for [Transloadit](http://transloadit.com/), a service focused on uploading and encoding images and videos. It has been battle-tested against hundreds of GB of file uploads from a large variety of clients and is considered production-ready. From e1e2470bab9f6096189ddde661f16f5ebd8a1c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Fri, 13 Jan 2017 07:15:53 +0100 Subject: [PATCH 14/29] Add maintainers wanted badge --- Readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 8e8840b8..0527b1f5 100644 --- a/Readme.md +++ b/Readme.md @@ -2,13 +2,15 @@ [![Build Status](https://secure.travis-ci.org/felixge/node-formidable.png?branch=master)](http://travis-ci.org/felixge/node-formidable) +[![Maintainers Wanted](https://img.shields.io/badge/maintainers-wanted-red.svg)](https://github.com/felixge/node-formidable/issues/412) + ## Purpose A node.js module for parsing form data, especially file uploads. ## Current status -**Maintainer Wanted:** Please see https://github.com/felixge/node-formidable/issues/412 +**Maintainers Wanted:** Please see https://github.com/felixge/node-formidable/issues/412 This module was developed for [Transloadit](http://transloadit.com/), a service focused on uploading and encoding images and videos. It has been battle-tested against hundreds of GB of file uploads from From 0fc85a981e7aa6d7b3b9e88befaf209c466a9b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Fri, 13 Jan 2017 07:16:08 +0100 Subject: [PATCH 15/29] whitespace --- Readme.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index 0527b1f5..5035fbf0 100644 --- a/Readme.md +++ b/Readme.md @@ -1,8 +1,6 @@ # Formidable -[![Build Status](https://secure.travis-ci.org/felixge/node-formidable.png?branch=master)](http://travis-ci.org/felixge/node-formidable) - -[![Maintainers Wanted](https://img.shields.io/badge/maintainers-wanted-red.svg)](https://github.com/felixge/node-formidable/issues/412) +[![Build Status](https://secure.travis-ci.org/felixge/node-formidable.png?branch=master)](http://travis-ci.org/felixge/node-formidable) [![Maintainers Wanted](https://img.shields.io/badge/maintainers-wanted-red.svg)](https://github.com/felixge/node-formidable/issues/412) ## Purpose From a230d94734a7853ede15ff33a98a2691eee89343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Tue, 13 Dec 2016 01:10:38 +0000 Subject: [PATCH 16/29] Updated dev deps a bit --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index d0d2ac75..4effe934 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,12 @@ "homepage": "https://github.com/felixge/node-formidable", "version": "1.0.17", "devDependencies": { - "gently": "0.8.0", - "findit": "0.1.1", - "hashish": "0.0.4", - "urun": "~0.0.6", - "utest": "0.0.3", - "request": "~2.11.4" + "gently": "^0.8.0", + "findit": "^0.1.2", + "hashish": "^0.0.4", + "urun": "^0.0.6", + "utest": "^0.0.8", + "request": "^2.11.4" }, "directories": { "lib": "./lib" From 1030bfa694872dc7cab1a39ce6ee71eb1f247dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Tue, 13 Dec 2016 01:16:52 +0000 Subject: [PATCH 17/29] Updated examples --- example/post.js | 9 +++++---- example/upload.js | 12 +++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/example/post.js b/example/post.js index f6c15a64..8458fbdc 100644 --- a/example/post.js +++ b/example/post.js @@ -1,7 +1,8 @@ -require('../test/common'); +var common = require('../test/common'); var http = require('http'), util = require('util'), - formidable = require('formidable'), + formidable = common.formidable, + port = common.port, server; server = http.createServer(function(req, res) { @@ -38,6 +39,6 @@ server = http.createServer(function(req, res) { res.end('404'); } }); -server.listen(TEST_PORT); +server.listen(port); -console.log('listening on http://localhost:'+TEST_PORT+'/'); +console.log('listening on http://localhost:'+port+'/'); diff --git a/example/upload.js b/example/upload.js index 050cdd9d..0b498d66 100644 --- a/example/upload.js +++ b/example/upload.js @@ -1,7 +1,9 @@ -require('../test/common'); +var common = require('../test/common'); var http = require('http'), util = require('util'), - formidable = require('formidable'), + os = require('os'), + formidable = common.formidable, + port = common.port, server; server = http.createServer(function(req, res) { @@ -19,7 +21,7 @@ server = http.createServer(function(req, res) { files = [], fields = []; - form.uploadDir = TEST_TMP; + form.uploadDir = os.tmpdir(); form .on('field', function(field, value) { @@ -43,6 +45,6 @@ server = http.createServer(function(req, res) { res.end('404'); } }); -server.listen(TEST_PORT); +server.listen(port); -console.log('listening on http://localhost:'+TEST_PORT+'/'); +console.log('listening on http://localhost:'+port+'/'); From d1ad9ff9ba87c494329b56b77a2007a2d55cdfd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Tue, 13 Dec 2016 01:14:25 +0000 Subject: [PATCH 18/29] Updated Buffer.write args --- benchmark/bench-multipart-parser.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmark/bench-multipart-parser.js b/benchmark/bench-multipart-parser.js index eab4c3c7..1978e588 100644 --- a/benchmark/bench-multipart-parser.js +++ b/benchmark/bench-multipart-parser.js @@ -59,8 +59,8 @@ function createMultipartBuffer(boundary, size) { , tail = '\r\n--'+boundary+'--\r\n' , buffer = new Buffer(size); - buffer.write(head, 'ascii', 0); - buffer.write(tail, 'ascii', buffer.length - tail.length); + buffer.write(head, 0, 'ascii'); + buffer.write(tail, buffer.length - tail.length, 'ascii'); return buffer; } From 3d7dcc00c8031fe0c529c402a28137d9f2b2371a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Tue, 13 Dec 2016 00:41:49 +0000 Subject: [PATCH 19/29] Changelog in the readme --- Readme.md | 121 ++++++------------------------------------------------ 1 file changed, 12 insertions(+), 109 deletions(-) diff --git a/Readme.md b/Readme.md index 2f0e8306..7d96cd86 100644 --- a/Readme.md +++ b/Readme.md @@ -4,7 +4,7 @@ ## Purpose -A node.js module for parsing form data, especially file uploads. +A Node.js module for parsing form data, especially file uploads. ## Current status @@ -274,6 +274,17 @@ Emitted when the entire request has been received, and all contained files have ## Changelog +### Unreleased yet + + * Fix DeprecationWarning about os.tmpDir() (Christian) + * Update `buffer.write` order of arguments for Node 7 (Kornel Lesiński) + * JSON Parser emits error events to the IncomingForm (alessio.montagnani) + * Improved Content-Disposition parsing (Sebastien) + * Access WriteStream of fs during runtime instead of include time (Jonas Amundsen) + * Use built-in toString to convert buffer to hex (Charmander) + * Add hash to json if present (Nick Stamas) + * Add license to package.json (Simen Bekkhus) + ### v1.0.14 * Add failing hash tests. (Ben Trask) @@ -312,114 +323,6 @@ Emitted when the entire request has been received, and all contained files have * Fix scope issue in incoming_forms (Sven Lito) * Fix file handle leak on error (OrangeDog) -### v1.0.11 - -* Calculate checksums for incoming files (sreuter) -* Add definition parameters to "IncomingForm" as an argument (Math-) - -### v1.0.10 - -* Make parts to be proper Streams (Matt Robenolt) - -### v1.0.9 - -* Emit progress when content length header parsed (Tim Koschützki) -* Fix Readme syntax due to GitHub changes (goob) -* Replace references to old 'sys' module in Readme with 'util' (Peter Sugihara) - -### v1.0.8 - -* Strip potentially unsafe characters when using `keepExtensions: true`. -* Switch to utest / urun for testing -* Add travis build - -### v1.0.7 - -* Remove file from package that was causing problems when installing on windows. (#102) -* Fix typos in Readme (Jason Davies). - -### v1.0.6 - -* Do not default to the default to the field name for file uploads where - filename="". - -### v1.0.5 - -* Support filename="" in multipart parts -* Explain unexpected end() errors in parser better - -**Note:** Starting with this version, formidable emits 'file' events for empty -file input fields. Previously those were incorrectly emitted as regular file -input fields with value = "". - -### v1.0.4 - -* Detect a good default tmp directory regardless of platform. (#88) - -### v1.0.3 - -* Fix problems with utf8 characters (#84) / semicolons in filenames (#58) -* Small performance improvements -* New test suite and fixture system - -### v1.0.2 - -* Exclude node\_modules folder from git -* Implement new `'aborted'` event -* Fix files in example folder to work with recent node versions -* Make gently a devDependency - -[See Commits](https://github.com/felixge/node-formidable/compare/v1.0.1...v1.0.2) - -### v1.0.1 - -* Fix package.json to refer to proper main directory. (#68, Dean Landolt) - -[See Commits](https://github.com/felixge/node-formidable/compare/v1.0.0...v1.0.1) - -### v1.0.0 - -* Add support for multipart boundaries that are quoted strings. (Jeff Craig) - -This marks the beginning of development on version 2.0 which will include -several architectural improvements. - -[See Commits](https://github.com/felixge/node-formidable/compare/v0.9.11...v1.0.0) - -### v0.9.11 - -* Emit `'progress'` event when receiving data, regardless of parsing it. (Tim Koschützki) -* Use [W3C FileAPI Draft](http://dev.w3.org/2006/webapi/FileAPI/) properties for File class - -**Important:** The old property names of the File class will be removed in a -future release. - -[See Commits](https://github.com/felixge/node-formidable/compare/v0.9.10...v0.9.11) - -### Older releases - -These releases were done before starting to maintain the above Changelog: - -* [v0.9.10](https://github.com/felixge/node-formidable/compare/v0.9.9...v0.9.10) -* [v0.9.9](https://github.com/felixge/node-formidable/compare/v0.9.8...v0.9.9) -* [v0.9.8](https://github.com/felixge/node-formidable/compare/v0.9.7...v0.9.8) -* [v0.9.7](https://github.com/felixge/node-formidable/compare/v0.9.6...v0.9.7) -* [v0.9.6](https://github.com/felixge/node-formidable/compare/v0.9.5...v0.9.6) -* [v0.9.5](https://github.com/felixge/node-formidable/compare/v0.9.4...v0.9.5) -* [v0.9.4](https://github.com/felixge/node-formidable/compare/v0.9.3...v0.9.4) -* [v0.9.3](https://github.com/felixge/node-formidable/compare/v0.9.2...v0.9.3) -* [v0.9.2](https://github.com/felixge/node-formidable/compare/v0.9.1...v0.9.2) -* [v0.9.1](https://github.com/felixge/node-formidable/compare/v0.9.0...v0.9.1) -* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0) -* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0) -* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0) -* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0) -* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0) -* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0) -* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0) -* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0) -* [v0.1.0](https://github.com/felixge/node-formidable/commits/v0.1.0) - ## License Formidable is licensed under the MIT license. From 97e908b73761de0cec10ff568c04238028577568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Tue, 13 Dec 2016 10:24:55 +0000 Subject: [PATCH 20/29] Install instructions --- Readme.md | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Readme.md b/Readme.md index 7d96cd86..6676470e 100644 --- a/Readme.md +++ b/Readme.md @@ -24,19 +24,12 @@ a large variety of clients and is considered production-ready. ## Installation -This is a low level package, and if you're using a high level framework such as Express, chances are it's already included in it. You can [read this discussion](http://stackoverflow.com/questions/11295554/how-to-disable-express-bodyparser-for-file-uploads-node-js) about how Formidable is integrated with Express. - -Via [npm](http://github.com/isaacs/npm): -``` -npm install formidable@latest -``` -Manually: -``` -git clone git://github.com/felixge/node-formidable.git formidable -vim my.js -# var formidable = require('./formidable'); +```sh +npm i -S formidable ``` +This is a low level package, and if you're using a high level framework such as Express, chances are it's already included in it. You can [read this discussion](http://stackoverflow.com/questions/11295554/how-to-disable-express-bodyparser-for-file-uploads-node-js) about how Formidable is integrated with Express. + Note: Formidable requires [gently](http://github.com/felixge/node-gently) to run the unit tests, but you won't need it for just using the library. ## Example From d0cce7ed57ebac01d3c72cf6b698d1be50edf6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Fri, 13 Jan 2017 15:36:11 +0000 Subject: [PATCH 21/29] CI badge --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 6676470e..0dba3997 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,6 @@ # Formidable -[![Build Status](https://secure.travis-ci.org/felixge/node-formidable.png?branch=master)](http://travis-ci.org/felixge/node-formidable) +[![Build Status](https://travis-ci.org/felixge/node-formidable.svg?branch=master)](https://travis-ci.org/felixge/node-formidable) ## Purpose From bbbc11244668c1af361a5d33ccc091e411cd2f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Sun, 15 Jan 2017 20:50:44 +0000 Subject: [PATCH 22/29] 1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5153e41a..1c004015 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "A node.js module for parsing form data, especially file uploads.", "homepage": "https://github.com/felixge/node-formidable", "license": "MIT", - "version": "1.0.17", + "version": "1.1.1", "devDependencies": { "gently": "^0.8.0", "findit": "^0.1.2", From 7a36a8e932044252fe648c81dbd8cf837d0178d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Sun, 15 Jan 2017 20:53:59 +0000 Subject: [PATCH 23/29] Updated changelog --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 0dba3997..8d51635c 100644 --- a/Readme.md +++ b/Readme.md @@ -267,7 +267,7 @@ Emitted when the entire request has been received, and all contained files have ## Changelog -### Unreleased yet +### v1.1.1 (2017-01-15) * Fix DeprecationWarning about os.tmpDir() (Christian) * Update `buffer.write` order of arguments for Node 7 (Kornel Lesiński) @@ -278,7 +278,7 @@ Emitted when the entire request has been received, and all contained files have * Add hash to json if present (Nick Stamas) * Add license to package.json (Simen Bekkhus) -### v1.0.14 +### v1.0.14 (2013-05-03) * Add failing hash tests. (Ben Trask) * Enable hash calculation again (Eugene Girshov) From b81d1c71cd3774419571c360db4312c965a57a13 Mon Sep 17 00:00:00 2001 From: Charlike Mike Reagent Date: Wed, 1 Mar 2017 16:39:18 +0200 Subject: [PATCH 24/29] Added max upload size for files (#357) * Added max upload size * Self reference for size fix --- lib/incoming_form.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/incoming_form.js b/lib/incoming_form.js index c5eace6b..9fffa48f 100644 --- a/lib/incoming_form.js +++ b/lib/incoming_form.js @@ -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 && os.tmpdir()) || os.tmpDir(); this.encoding = opts.encoding || 'utf-8'; @@ -39,6 +40,7 @@ function IncomingForm(opts) { this._parser = null; this._flushing = 0; this._fieldsSize = 0; + this._fileSize = 0; this.openedFiles = []; return this; @@ -214,6 +216,11 @@ IncomingForm.prototype.handlePart = function(part) { this.openedFiles.push(file); part.on('data', function(buffer) { + self._fileSize += buffer.length; + if (self._fileSize > self.maxFileSize) { + self._error(new Error('maxFileSize exceeded, received '+self._fileSize+' bytes of file data')); + return; + } if (buffer.length == 0) { return; } @@ -552,4 +559,3 @@ IncomingForm.prototype._maybeEnd = function() { this.emit('end'); }; - From 05e4743078f0a10cc556ec7351a629643e2b95b9 Mon Sep 17 00:00:00 2001 From: lyyh3c Date: Thu, 30 Mar 2017 23:57:42 +0800 Subject: [PATCH 25/29] to solve EISDIR error (#424) * to solve EISDIR error to solve EISDIR error when trying to submit a form with no file selected. * del .ideal and modify incoming_form remove needless .idea things and change the condition to !part.filename * remove needless .idea remove needless .idea --- lib/incoming_form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/incoming_form.js b/lib/incoming_form.js index 9fffa48f..8eed298c 100644 --- a/lib/incoming_form.js +++ b/lib/incoming_form.js @@ -182,7 +182,7 @@ IncomingForm.prototype.onPart = function(part) { IncomingForm.prototype.handlePart = function(part) { var self = this; - if (part.filename === undefined) { + if (!part.filename) { var value = '' , decoder = new StringDecoder(this.encoding); From 6b99fab66d3c5b8a2b5ae827ecdd6f706319ee9b Mon Sep 17 00:00:00 2001 From: Greg Walden Date: Thu, 7 Sep 2017 16:47:47 -0400 Subject: [PATCH 26/29] update readme to reflect current state of Express --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 8d51635c..bbe73553 100644 --- a/Readme.md +++ b/Readme.md @@ -28,7 +28,7 @@ a large variety of clients and is considered production-ready. npm i -S formidable ``` -This is a low level package, and if you're using a high level framework such as Express, chances are it's already included in it. You can [read this discussion](http://stackoverflow.com/questions/11295554/how-to-disable-express-bodyparser-for-file-uploads-node-js) about how Formidable is integrated with Express. +This is a low-level package, and if you're using a high-level framework it may already be included. However, [Express v4](http://expressjs.com) does not include any multipart handling, nor does [body-parser](https://github.com/expressjs/body-parser). Note: Formidable requires [gently](http://github.com/felixge/node-gently) to run the unit tests, but you won't need it for just using the library. From 549d7f043f36d2bebcdf9fc889f76cf48a3ec812 Mon Sep 17 00:00:00 2001 From: Lukas Eipert Date: Tue, 26 Sep 2017 08:50:37 +0200 Subject: [PATCH 27/29] Remove duplicate license field from package.json --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 1c004015..7f0ee0ff 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,5 @@ "bugs": { "url": "http://github.com/felixge/node-formidable/issues" }, - "optionalDependencies": {}, - "license": "MIT" + "optionalDependencies": {} } From c7e47cd640026d12b64b9270ecb60f6c2585c337 Mon Sep 17 00:00:00 2001 From: Kornel Date: Tue, 26 Sep 2017 10:21:52 +0200 Subject: [PATCH 28/29] Revert "to solve EISDIR error (#424)" This reverts commit 05e4743078f0a10cc556ec7351a629643e2b95b9. --- lib/incoming_form.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/incoming_form.js b/lib/incoming_form.js index 8eed298c..8d96bfe1 100644 --- a/lib/incoming_form.js +++ b/lib/incoming_form.js @@ -182,7 +182,8 @@ IncomingForm.prototype.onPart = function(part) { IncomingForm.prototype.handlePart = function(part) { var self = this; - if (!part.filename) { + // This MUST check exactly for undefined. You can not change it to !part.filename. + if (part.filename === undefined) { var value = '' , decoder = new StringDecoder(this.encoding); From 5ddd6d34bc51f9e50c0e6116b48ad40345de7d9e Mon Sep 17 00:00:00 2001 From: Vitalii Date: Tue, 19 Dec 2017 19:49:51 +0200 Subject: [PATCH 29/29] Fix using closed _writeStream when error is occurred (#357) When fileMaxSize reached _error() calls _writeStream.destroy() which turns into unhandled exception. --- lib/file.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/file.js b/lib/file.js index 99744516..50d34c09 100644 --- a/lib/file.js +++ b/lib/file.js @@ -56,6 +56,11 @@ File.prototype.write = function(buffer, cb) { if (self.hash) { self.hash.update(buffer); } + + if (this._writeStream.closed) { + return cb(); + } + this._writeStream.write(buffer, function() { self.lastModifiedDate = new Date(); self.size += buffer.length;