diff --git a/src/@types/Other.ts b/src/@types/Other.ts index 7b19551..4bcc4f4 100644 --- a/src/@types/Other.ts +++ b/src/@types/Other.ts @@ -1,6 +1,9 @@ +export type ReqOptions = { + headers?: {[key: string]: string} | null +} + export type RequestOptions = { headers?: { [key: string]: string }, - } export type Res = { diff --git a/src/pages/home/Profile.tsx b/src/pages/home/Profile.tsx index 385fdf4..2daa92e 100644 --- a/src/pages/home/Profile.tsx +++ b/src/pages/home/Profile.tsx @@ -98,10 +98,11 @@ const Profile = () => { button.disabled = true; const body = new FormData(); - body.set('file', file, file.name); - // body.set('name', file.name); + body.append('file', file, file.name); - const response = await post('/api/user/avatar', body, { headers: {} }); + const response = await post('/api/user/avatar', body, { + headers: null + }); if (!response.success) setError(response.message || 'Unknown error'); else setFile(null); button.disabled = false; diff --git a/src/util/Util.ts b/src/util/Util.ts index d3fbd01..8d2a9ff 100644 --- a/src/util/Util.ts +++ b/src/util/Util.ts @@ -1,5 +1,5 @@ import { User } from "../@types/ApiStructures"; -import { RequestOptions, ClientSettings, Res } from "../@types/Other"; +import { RequestOptions, ClientSettings, Res, ReqOptions } from "../@types/Other"; type HttpOpts = { body?: string, @@ -66,7 +66,7 @@ const parseResponse = async (response: Response): Promise => { return { ...base, message: await response.text() }; }; -export const post = async (url: string, body?: object | string, opts: RequestOptions = {}) => { +export const post = async (url: string, body?: object | string, opts: ReqOptions = {}) => { const options: HttpOpts & RequestOptions = { method: 'post'