Skip to content
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

<input ... multiple> doesn't work #17

Closed
flplv opened this issue Feb 7, 2017 · 4 comments
Closed

<input ... multiple> doesn't work #17

flplv opened this issue Feb 7, 2017 · 4 comments

Comments

@flplv
Copy link
Contributor

flplv commented Feb 7, 2017

In case you have a multiple file selection input, such as

<input type="file" name="uploadedFiles" multiple>

it won't work. Multiple files will be uploaded, but they will not appear in the files tree since this line

return req.files[fieldname] = {

(index.js line 53)
will be called one time per file, replacing the last file from the object.

I'll submit a patch in this Issue soon.

@flplv
Copy link
Contributor Author

flplv commented Feb 7, 2017

This is a possible patch: flplv@2dcbb13?diff=split

The problem is that it will change the req.files[fieldname] from an Object to an Array, which will break backward compatibility.

I believe the correct solution is to store files in req.files[fieldname + "Multiple"], I just couldn't find a way to check if input is multiple file...

@r3wt
Copy link
Contributor

r3wt commented Feb 7, 2017

@flplv it can be done without breaking bc:

if(req.files.hasOwnProperty(fieldName) && req.files[fieldName] instanceof Array == false){
    var tmp = req.files[fieldName];//temporarily move first file into var
    req.files[fieldName] = [tmp]; //reassign to array containing first file
}
else if(req.files.hasOwnProperty(fieldName) && req.files[fieldName] instanceof Array){
    req.files[fieldName].push( newFileHere ); //push new file into array
} else {
    //treat as single file, as we do now
}

I hope this makes sense. i'm in the bed lol

@flplv
Copy link
Contributor Author

flplv commented Feb 7, 2017

Thanks.. gonna test it and create a PR.

@richardgirges
Copy link
Owner

I believe #18 fixes this. Updated and published to NPM registry.

This was referenced Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants