Fix content-type for formdata

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-05-12 07:58:47 +02:00
parent f3165877f2
commit afa677a375
4 changed files with 9 additions and 10 deletions

View File

@ -37,7 +37,7 @@ const uploadMediaV1 = (body: FormData, onUploadProgress = noOp) =>
api(getState)('/api/v1/media', {
method: 'POST',
body,
headers: { 'Content-Type': 'multipart/form-data' },
headers: { 'Content-Type': '' },
// }, {
// onUploadProgress: onUploadProgress,
});
@ -47,7 +47,7 @@ const uploadMediaV2 = (body: FormData, onUploadProgress = noOp) =>
api(getState)('/api/v2/media', {
method: 'POST',
body,
headers: { 'Content-Type': 'multipart/form-data' },
headers: { 'Content-Type': '' },
// }, {
// onUploadProgress: onUploadProgress,
});

View File

@ -23,9 +23,7 @@ function useCreateGroup() {
return api('/api/v1/groups', {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
},
headers: { 'Content-Type': '' },
body: formData,
});
}, { schema: groupSchema });

View File

@ -22,9 +22,7 @@ function useUpdateGroup(groupId: string) {
return api(`/api/v1/groups/${groupId}`, {
method: 'PUT',
headers: {
'Content-Type': 'multipart/form-data',
},
headers: { 'Content-Type': '' },
body: formData,
});
}, { schema: groupSchema });

View File

@ -45,13 +45,16 @@ export const getFetch = (accessToken?: string | null, baseURL: string = '') =>
const fullPath = buildFullPath(input.toString(), isURL(BuildConfig.BACKEND_URL) ? BuildConfig.BACKEND_URL : baseURL, init?.params);
const headers = new Headers(init?.headers);
const contentType = headers.get('Content-Type') || 'application/json';
if (accessToken) {
headers.set('Authorization', `Bearer ${accessToken}`);
}
headers.set('Content-Type', contentType);
if (headers.get('Content-Type') === '') {
headers.delete('Content-Type');
} else {
headers.set('Content-Type', headers.get('Content-Type') || 'application/json');
}
return fetch(fullPath, {
...init,