-
-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force form.multiples to always return array #315
Conversation
This would close #292. |
@@ -91,7 +91,10 @@ IncomingForm.prototype.parse = function(req, cb) { | |||
} | |||
files[name].push(file); | |||
} else { | |||
files[name] = file; | |||
if (!Array.isArray(files[name])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!Array.isArray(files[name])
is implied by !files[name]
; this would just be files[name] = [file];
. (Still, given the Array.isArray
check above, it looks as if the intent was for single files not to be arrays.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Contains logical duplication that can be simplified:
It all can be simplified down to this:
if (this.multiples) {
if (!files[name]) {
files[name] = [];
}
files[name].push(file);
}
Note that it will do the same (will return always an array). But has no complicated/odd else blocks.
Anyway it should also be documented as well, and perhaps may need a version change (as its not backward compatible).
You right requested change, but it was around 4 years? Isn't better to just make another PR, or actually just update this one directly. |
Requirements for this feature:
|
That’s how it already works. |
So, we can make it configurable, e.g. provide a setting which makes it always return array. Feature request? |
Ooops, I just merged #380, should it be supported only behind the |
Okay, my bad, that's for |
I propose: Make the multiple always return arrays for both fields and files. It does not need a new flag and is backwards compatible as application using multiples: true should already have an if else for arrays or objects. I can make a new PR. |
Continue disscussion #292 |
When uploading one file to a formidable with form.multiples = true then the req.files.[name] would just be the file instead should be array of files as suggested by the documentation.