feat: add individual content types for formadata (#4550)

Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
Akash K
2024-11-24 19:36:10 +05:30
committed by GitHub
parent b78cd57884
commit c74c42ebaf
10 changed files with 161 additions and 10 deletions

View File

@@ -1,12 +1,27 @@
type FormDataEntry = {
key: string
contentType?: string
value: string | Blob
}
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
}

View File

@@ -72,13 +72,24 @@ const buildHarPostParams = (
<Har.Param>{
name: entry.key,
fileName: entry.key, // TODO: Blob doesn't contain file info, anyway to bring file name here ?
contentType: file.type,
contentType: entry.contentType ? entry.contentType : file?.type,
}
)
}
if (entry.contentType) {
return {
name: entry.key,
value: entry.value,
fileName: entry.key,
contentType: entry.contentType,
}
}
return {
name: entry.key,
value: entry.value,
contentType: entry.contentType,
}
})
}

View File

@@ -427,6 +427,7 @@ export const resolvesEnvsInBody = (
value: entry.isFile
? entry.value
: parseTemplateString(entry.value, env.variables, false, true),
contentType: entry.contentType,
}
),
}
@@ -512,11 +513,13 @@ function getFinalBodyFromRequest(
? x.value.map((v) => ({
key: parseTemplateString(x.key, envVariables),
value: v as string | Blob,
contentType: x.contentType,
}))
: [
{
key: parseTemplateString(x.key, envVariables),
value: parseTemplateString(x.value, envVariables),
contentType: x.contentType,
},
]
),