Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix(common): handle File objects in HAR postData text resolution (#5917)

Shekhu☺️b728f5da2420
diff --git a/packages/hoppscotch-common/src/helpers/new-codegen/har.ts b/packages/hoppscotch-common/src/helpers/new-codegen/har.ts
index b8c9e49cb..c9fc285c8 100644
--- a/packages/hoppscotch-common/src/helpers/new-codegen/har.ts
+++ b/packages/hoppscotch-common/src/helpers/new-codegen/har.ts
@@ -114,6 +114,29 @@ const buildHarPostData = (req: HoppRESTRequest): Har.PostData | undefined => {
}
}
+ // application/octet-stream bodies are File | null; emit @filename for file uploads
+ if (req.body.contentType === "application/octet-stream") {
+ const file = req.body.body
+
+ if (!file) {
+ return {
+ mimeType: req.body.contentType,
+ text: "",
+ }
+ }
+
+ // `path` exists in some desktop runtimes; `name` is the standard File field.
+ const filename =
+ "path" in file && typeof file.path === "string" && file.path
+ ? file.path
+ : file.name || "<binary-file>"
+
+ return {
+ mimeType: req.body.contentType,
+ text: `@${filename}`,
+ }
+ }
+
return {
mimeType: req.body.contentType, // Let's assume by default content type is JSON
text: (req.body.body as string) ?? "",