feat: add individual content types for formadata (#4550)
Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import { HoppCLIError } from "./errors";
|
||||
export type FormDataEntry = {
|
||||
key: string;
|
||||
value: string | Blob;
|
||||
contentType?: string;
|
||||
};
|
||||
|
||||
export type HoppEnvPair = Environment["variables"][number];
|
||||
|
||||
@@ -52,7 +52,21 @@ const getValidRequests = (
|
||||
export const toFormData = (values: FormDataEntry[]) => {
|
||||
const formData = new FormData();
|
||||
|
||||
values.forEach(({ key, value }) => formData.append(key, value));
|
||||
values.forEach(({ key, value, contentType }) => {
|
||||
if (contentType) {
|
||||
formData.append(
|
||||
key,
|
||||
new Blob([value], {
|
||||
type: contentType,
|
||||
}),
|
||||
key
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
formData.append(key, value);
|
||||
});
|
||||
|
||||
return formData;
|
||||
};
|
||||
|
||||
@@ -422,11 +422,13 @@ function getFinalBodyFromRequest(
|
||||
? x.value.map((v) => ({
|
||||
key: parseTemplateString(x.key, resolvedVariables),
|
||||
value: v as string | Blob,
|
||||
contentType: x.contentType,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
key: parseTemplateString(x.key, resolvedVariables),
|
||||
value: parseTemplateString(x.value, resolvedVariables),
|
||||
contentType: x.contentType,
|
||||
},
|
||||
]
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user