-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
formData() helper method does not support appending data to the same key #119
Comments
Hey @tonisostrat,
Passing the const files = getCachedFiles();
getWretch()
.url("")
.formData({ files })
.post(); |
Thank you for the prompt reply! Unfortunately passing the array in as-is does not work - if you take a look at my original post that is exactly what I did. Using the array generates a request body where the field name is I have put together a quick demonstration here. The queries obviously fail but if you open up your browser's console you can inspect the body content and the difference becomes evident. |
Ah I'm sorry my bad I replied too quickly 🤦. So yeah in this case this is a limitation and you will need to use |
Gotcha, at least I know I'm not going crazy :) Is there any chance you'll consider implementing this functionality? The helper method is great and really cuts down on LoC compared to instantiating the |
So if I recall correctly the reason why the brackets ( In retrospective I think that was a bad move, but changing it would be breaking. I'm definitely planning to release 2.0 at some point and rewrite the whole lib, I just cannot tell when this will happen yet. But when it does I'll make sure to include this change 😉. |
Should solve #119 BREAKING CHANGE: - Does not append [] anymore when appending an array through the .formData helper.
Should be fixed with the v2. |
I seem to have run into a limitation of the
formData()
builder method. Our (Spring) back-end expects an array-type field containing all user-submitted files. It's trivial to achieve with the defaultFormData
object:which produces the following multipart payload (only the relevant lines have been kept):
but it does not work with
wretch
's custom helper method:which results in the following payload:
and the data on the back-end is
null
.Obviously it's also impossible to add the files separately under the same key as the input for the method is an
object
:Is there some part of the documentation that I've missed or is this a genuine limitation?
The text was updated successfully, but these errors were encountered: