mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
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:
@@ -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;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user