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.
This commit is contained in:
2025-08-29 09:49:29 -06:00
parent 18d656529c
commit 59d4c56a48

View File

@@ -14,9 +14,6 @@ import createFetchClient from "openapi-react-query";
// The actual URL will be set via middleware in ApiAuthProvider // The actual URL will be set via middleware in ApiAuthProvider
export const client = createClient<paths>({ export const client = createClient<paths>({
baseUrl: "http://127.0.0.1:1250", baseUrl: "http://127.0.0.1:1250",
headers: {
"Content-Type": "application/json",
},
}); });
// Create the React Query client wrapper // Create the React Query client wrapper
@@ -31,6 +28,13 @@ client.use({
if (currentAuthToken) { if (currentAuthToken) {
request.headers.set("Authorization", `Bearer ${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; return request;
}, },
}); });