diff --git a/src/shared/lib/uploadFile.ts b/src/shared/lib/uploadFile.ts new file mode 100644 index 0000000..3713a29 --- /dev/null +++ b/src/shared/lib/uploadFile.ts @@ -0,0 +1,23 @@ +import { z } from "zod"; +import { getAxios } from "./getAxios"; + +const fileSchema = z.object({ + url: z.string(), +}); + +export async function uploadFile(file: File) { + const axios = getAxios(); + + try { + const data = new FormData(); + data.set("file", file); + + const response = await axios.post("/s3", data, { + headers: { "Content-Type": "multipart/form-data" }, + }); + + return fileSchema.parse(response.data).url; + } catch { + return null; + } +}