Closed NickeNicrad closed 6 months ago
axios v0.27.0 has automatic serialization to FormData, but unfortunately apisauce hasn't been updated to that version.
Edit: This PR would fix that: https://github.com/infinitered/apisauce/pull/288
here is my workaround to make a general post function that can take form data:
const post = apiClient.post;
apiClient.post = async (url, data, axiosConfig = {}, contentType) => {
if (contentType === "multipart/form-data") {
axiosConfig.headers = {
...axiosConfig.headers,
"Content-Type": "multipart/form-data",
};
const formData = new FormData();
Object.keys(data).forEach((key) => {
formData.append(key, data[key]);
});
data = formData;
}
const response = await post(url, data, axiosConfig);
return response;
};
I do this if it's any help