From 42deec79f044e262ffcf60394972f0b2c9753dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=94=D1=83=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Mon, 24 Mar 2025 13:13:17 +0300 Subject: [PATCH] Added processing of array of properties, for adding to formData sequentially, element by element --- .../base/http-clients/fetch-http-client.ejs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/templates/base/http-clients/fetch-http-client.ejs b/templates/base/http-clients/fetch-http-client.ejs index a1db3833..9a05fc0d 100644 --- a/templates/base/http-clients/fetch-http-client.ejs +++ b/templates/base/http-clients/fetch-http-client.ejs @@ -106,16 +106,28 @@ export class HttpClient { [ContentType.Text]: (input:any) => input !== null && typeof input !== "string" ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((formData, key) => { - const property = input[key]; - formData.append( + const property = input[key]; + + // array of property should be added item by item in formData with the same key + if (Array.isArray(property)) { + for (const item of property) { + formData.append( key, - property instanceof Blob ? - property : - typeof property === "object" && property !== null ? - JSON.stringify(property) : - `${property}` + item instanceof Blob ? item : typeof item === "object" && item !== null ? JSON.stringify(item) : `${item}` + ); + } + } else { + formData.append( + key, + property instanceof Blob + ? property + : typeof property === "object" && property !== null + ? JSON.stringify(property) + : `${property}` ); - return formData; + } + + return formData; }, new FormData()), [ContentType.UrlEncoded]: (input: any) => this.toQueryString(input), }