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

The key for and array is "files[]" in place of "files" #146

Open
jacsebastien opened this issue Feb 17, 2017 · 3 comments
Open

The key for and array is "files[]" in place of "files" #146

jacsebastien opened this issue Feb 17, 2017 · 3 comments

Comments

@jacsebastien
Copy link

jacsebastien commented Feb 17, 2017

I wonder why, when we upload multiple files, the request is like

files[]:[{....},{...}]

and not simply
files:[{....},{...}]

When I upload only one file everything works well but with multiple files I have troubles for selecting them in my back-end with multer or multiparty due to that special key. I can't select a key that contain special characters like [].

I tried to edit paramNamespace or paramName but that doesn't fix the problem.

With multer I have this error:
{"code":"LIMIT_UNEXPECTED_FILE","field":"files[]","storageErrors":[]}

When I reopen Uploader object and edit createFormData method to remove the [] in the key everything works well.

Am I the only one that encounter this problem?

@tythewebguy
Copy link

I think this a Rails convention for passing arrays so the framework knows the data should be an array. But I'm not a Rails guy, so the origin may be something else. But I've seen this syntax used with Rails.

@digitaltoad
Copy link
Member

digitaltoad commented Mar 9, 2017

This is a convention that was used in PHP and indeed with Rails as well as other languages/frameworks. It isn't a standard as far as I know. Depending on what you are using on the server, you will either use the key without brackets or with. I'm up for suggestions on this. Do I construct the names programmatically or continue with the current implementation?

@jacsebastien
Copy link
Author

Ok thank you for the reply.
I think this will be nice if the format of the key can be defined by the developer that will use your plugin in depending on his backend.

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