[ACS-11928] convert ReadStream to Blob before appending to FormData (#11987)

* [ACS-11928] convert ReadStream to Blob before appending to FormData

* [ACS-11928] comments removed from toFormDataValue

* Trigger Build

* [ACS-11928] added unit tests and changed the blob variable name to data

* [ACS-11928] unit tests updated

* [ACS-11928] updated type in multipart form data upload

* [ACS-11928] sonar cloud fix
This commit is contained in:
Adam Świderski
2026-06-15 13:15:33 +02:00
committed by GitHub
parent 5dd709ed58
commit 8f5099e822
2 changed files with 147 additions and 1 deletions
+26 -1
View File
@@ -367,7 +367,12 @@ export class FetchHttpClient implements HttpClient {
const normalizedParams = FetchHttpClient.normalizeParams(formParams);
const formData = new FormData();
for (const [key, value] of Object.entries(normalizedParams)) {
formData.append(key, value as any);
const { data, filename } = FetchHttpClient.toFormDataValue(value);
if (filename) {
formData.append(key, data, filename);
} else {
formData.append(key, data);
}
}
return formData;
}
@@ -524,4 +529,24 @@ export class FetchHttpClient implements HttpClient {
}
return false;
}
private static toFormDataValue(value: any): { data: any; filename?: string } {
if (value && typeof value === 'object' && value.path && typeof value.path === 'string' && !(value instanceof Blob)) {
try {
const nodeFs = Function('return require("fs")')();
const nodePath = Function('return require("path")')();
const buffer = nodeFs.readFileSync(value.path);
const filename: string = nodePath.basename(value.path);
return { data: new Blob([buffer]), filename };
} catch {
return { data: value };
}
}
if (typeof Buffer === 'function' && value instanceof Buffer) {
return { data: new Blob([value]) };
}
return { data: value };
}
}