From 59d4c56a485e3eb274b94cab07fcc5bb682040f2 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Fri, 29 Aug 2025 09:49:29 -0600 Subject: [PATCH] fix: correct content-type header for FormData uploads Previously, the API client was setting a default Content-Type of application/json for all requests, which broke file uploads that need multipart/form-data. Now the client only sets application/json when the body is not FormData, allowing FormData to automatically set the correct multipart boundary. --- www/app/lib/apiClient.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/www/app/lib/apiClient.tsx b/www/app/lib/apiClient.tsx index 0a167f68..cc1e4ca7 100644 --- a/www/app/lib/apiClient.tsx +++ b/www/app/lib/apiClient.tsx @@ -14,9 +14,6 @@ import createFetchClient from "openapi-react-query"; // The actual URL will be set via middleware in ApiAuthProvider export const client = createClient({ baseUrl: "http://127.0.0.1:1250", - headers: { - "Content-Type": "application/json", - }, }); // Create the React Query client wrapper @@ -31,6 +28,13 @@ client.use({ if (currentAuthToken) { request.headers.set("Authorization", `Bearer ${currentAuthToken}`); } + // Only set Content-Type if not already set (FormData will set its own boundary) + if ( + !request.headers.has("Content-Type") && + !(request.body instanceof FormData) + ) { + request.headers.set("Content-Type", "application/json"); + } return request; }, });