Skip to content
This repository

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

Closed
lazd opened this Issue · 3 comments

3 participants

Larry Davis Jonathan Ong TJ Holowaychuk
Larry Davis
lazd commented

When uploading multiple files:

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

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

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


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


------WebKitFormBoundarysdCznBBo6SohkEj8
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.

Jonathan Ong
Collaborator

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

TJ Holowaychuk

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

Jonathan Ong
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.