feat: add individual content types for formadata (#4550)
Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
]
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user