From b5ae2b37cdd7eb639ad1fc66810d6f482a623fef Mon Sep 17 00:00:00 2001 From: Akash Kava <39438041+ackava@users.noreply.github.com> Date: Sun, 17 Dec 2023 16:08:46 +0530 Subject: [PATCH] Added support for file --- src/services/FetchBuilder.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/services/FetchBuilder.ts b/src/services/FetchBuilder.ts index d6153e33..26dfc83f 100644 --- a/src/services/FetchBuilder.ts +++ b/src/services/FetchBuilder.ts @@ -54,9 +54,18 @@ export default class FetchBuilder { }); } - public form(name: string, value: string) { + public form(name: string, value: Blob); + public form(name: string, value: Blob, fileName: string); + public form(name: string, value: string | Blob, fileName?: string ) { const body = this.request.body as FormData ?? new FormData(); - body.append(name, value); + if (fileName) { + if (typeof value === "string") { + throw new Error("value must be a blob with content type set correctly."); + } + body.append(name, value as Blob, fileName) + } else { + body.append(name, value); + } return this.append ({ body }); }