Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

req.files.someFiles array does not match order of files as sent by the client #1529

lazd opened this Issue Mar 4, 2013 · 3 comments


None yet
3 participants

lazd commented Mar 4, 2013

When uploading multiple files:

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

The request payload will contain the files in a given order:

Content-Disposition: form-data; name="someFiles"; filename="file1.jpg"
Content-Type: image/jpeg

Content-Disposition: form-data; name="someFiles"; filename="file2.jpeg"
Content-Type: image/jpeg

Content-Disposition: form-data; name="someFiles"; filename="file3.jpeg"
Content-Type: image/jpeg

When handling the request, the order of req.files.someField does not match the order of the request payload.

This may be a connect or node-formidable bug, but I am filing against express as I have not done isolated testing.

Background: The goal is to associate an uploaded file with a user-provided label. The labels are provided via a series of text fields with named someFileLabels that are added to the form when the someFiles input changes.

The request that is sent to the server contains the files and the labels in the same order.

However, when the request is handled on the server, the indicies of req.files.someFiles do not match those of req.body.someFileLabels (which matches the order sent), so it is impossible to associate the label with the file.

It is possible for filename and size to be identical, so it's not easy to hack around this by naming the label fields according to the filename.


jonathanong commented Sep 7, 2013

express uses multipart as of 3.4. what you can do is submit a pull request for a test of this.


tj commented Sep 7, 2013

hmm interesting yeah I've never noticed this actually, but if it's still a problem in 3.4 let us know


jonathanong commented Oct 2, 2013

closing, especially since we use a different multipart parser now. please reopen with a test case if it's still an issue.

@jonathanong jonathanong closed this Oct 2, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment