Skip to content

Commit c1b22ef

Browse files
committed
fix: handle arrays properly in FormData
When FormData contains arrays (e.g., multiple file uploads), the current implementation incorrectly stringifies the entire array instead of appending each item individually. This fix: - Detects when a property is an array - Iterates through each array item - Properly appends each file/blob individually to FormData - Preserves non-file array items by JSON.stringify-ing them individually This enables proper multi-file uploads and array handling in FormData, which is essential for APIs that accept multiple attachments or files.
1 parent 291d9de commit c1b22ef

File tree

30 files changed

+1320
-920
lines changed

30 files changed

+1320
-920
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,12 @@ export class HttpClient<SecurityDataType = unknown> {
113113

114114
return Object.keys(input || {}).reduce((formData, key) => {
115115
const property = input[key];
116-
formData.append(
117-
key,
118-
property instanceof Blob ?
119-
property :
120-
typeof property === "object" && property !== null ?
121-
JSON.stringify(property) :
122-
`${property}`
123-
);
116+
const propertyContent = property instanceof Array ? property : [property];
117+
118+
for (const formItem of propertyContent) {
119+
const isFileType = formItem instanceof Blob || formItem instanceof File;
120+
formData.append(key, isFileType ? formItem : JSON.stringify(formItem));
121+
}
124122
return formData;
125123
}, new FormData());
126124
},

0 commit comments

Comments
 (0)