Fixed file upload

This commit is contained in:
Benjamin Sherriff
2023-10-24 08:42:21 -04:00
parent f3eff8e310
commit ece4154b4e
7 changed files with 41 additions and 30 deletions

View File

@@ -21,19 +21,23 @@ interface PostOptions {
export async function post(endpoint: string, body: any, options?: PostOptions): Promise<Response> {
const url = `${baseURL}/${endpoint}`;
const headers = options?.headers || {};
let response;
if (!options?.type || options.type === 'json') {
body = JSON.stringify(body);
headers['Content-Type'] = 'application/json';
} else if (options.type === 'form') {
headers['Content-Type'] = 'multipart/form-data';
response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
credentials: 'include',
body: JSON.stringify(body)
});
} else {
response = await fetch(url, {
method: 'POST',
credentials: 'include',
body
});
}
const response = await fetch(url, {
method: 'POST',
headers: headers,
credentials: 'include',
body
});
return response;
}