-
-
Notifications
You must be signed in to change notification settings - Fork 394
feat(core): add better support for form-data arrays #2026
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
feat(core): add better support for form-data arrays #2026
Conversation
I'll check it later! |
@AllieJonsson not related to the pull request. Could you check your discord messages when you have the time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AllieJonsson
I added comments 👍
could you check it ?
} | ||
``` | ||
|
||
Type `explode` setting results in the following generated code: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may not be necessary.
If necessary, why not consider specifying explode
separately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if this is removed, it can be made into a simple option like override.formData.serializeWithBrackets: true
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that doesn't allow you to specify how body
data in multipart/form-data
requests are serialized, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that if override.formData.serializeWithBrackets
was set to true
, brackets would be added, and if it was set to false
, it would behave as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was thinking about the explode
, how would you configure it to explode form data?
What I need for it to work with my ASP.Net backend is instead of
data.forEach(
(value, index) => {
formData.append(
`receptionFacilitiesPerFaction`,
/*
* value is of type
* {
* fractionId: number
* receptionFacilityIds: number[]
* }
*/
JSON.serialize(value),
);
},
);
I need to set
data.forEach(
(value, index) => {
formData.append(
`receptionFacilitiesPerFaction[${index}].fractionId`,
value.fractionId.toString(),
);
value.receptionFacilityIds.forEach((v, rIndex) => {
formData.append(
`receptionFacilitiesPerFaction[${index}].receptionFacilityIds[${rIndex}]`,
v.toString(),
);
});
},
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, so ASP.net
can't accept it unless it's in a format like receptionFacilitiesPerFaction[0]&receptionFacilitiesPerFaction[1]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was surprised as well, I couldn't get it to work with sending json objects in a multipart/form-data, so I asked ChatGPT, which gave me this solution, and it worked!
https://chatgpt.com/share/67ff8e02-1fb0-8000-901b-61e336ddad0e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I didn't know that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AllieJonsson
Okey, then we already have override.formData
so let's just move up the options level like override.formData.arrayHandling
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good!
@AllieJonsson |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Status
READY
Description
Fixes #1417 (appending [] to formData key name) and adds support for exploding the formData properties as well.
I need this in my current project at work, so I added it here as well.