From 24e2637408e583d3340c7729f31426ccfd6e8f3b Mon Sep 17 00:00:00 2001 From: James Collins Date: Wed, 22 Feb 2023 20:22:38 +1000 Subject: [PATCH] support file uploading --- resources/js/helpers/api.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/resources/js/helpers/api.ts b/resources/js/helpers/api.ts index dcb7e14..47b7ec2 100644 --- a/resources/js/helpers/api.ts +++ b/resources/js/helpers/api.ts @@ -58,7 +58,19 @@ export const api = { } if (options.body && typeof options.body === "object") { - options.body = JSON.stringify(options.body); + if (options.body instanceof FormData) { + if ( + Object.prototype.hasOwnProperty.call( + options.headers, + "Content-Type" + ) + ) { + // remove the "Content-Type" key from the headers object + delete options.headers["Content-Type"]; + } + } else { + options.body = JSON.stringify(options.body); + } } const fetchOptions: RequestInit = {