Skip to content

Commit 42deec7

Browse files
committed
Added processing of array of properties, for adding to formData sequentially, element by element
1 parent 760a5b6 commit 42deec7

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

templates/base/http-clients/fetch-http-client.ejs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,28 @@ export class HttpClient<SecurityDataType = unknown> {
106106
[ContentType.Text]: (input:any) => input !== null && typeof input !== "string" ? JSON.stringify(input) : input,
107107
[ContentType.FormData]: (input: any) =>
108108
Object.keys(input || {}).reduce((formData, key) => {
109-
const property = input[key];
110-
formData.append(
109+
const property = input[key];
110+
111+
// array of property should be added item by item in formData with the same key
112+
if (Array.isArray(property)) {
113+
for (const item of property) {
114+
formData.append(
111115
key,
112-
property instanceof Blob ?
113-
property :
114-
typeof property === "object" && property !== null ?
115-
JSON.stringify(property) :
116-
`${property}`
116+
item instanceof Blob ? item : typeof item === "object" && item !== null ? JSON.stringify(item) : `${item}`
117+
);
118+
}
119+
} else {
120+
formData.append(
121+
key,
122+
property instanceof Blob
123+
? property
124+
: typeof property === "object" && property !== null
125+
? JSON.stringify(property)
126+
: `${property}`
117127
);
118-
return formData;
128+
}
129+
130+
return formData;
119131
}, new FormData()),
120132
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
121133
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy