upload file

This commit is contained in:
Robert 2024-03-11 23:46:24 +07:00
parent b652cf49bf
commit 42253c3220
No known key found for this signature in database
GPG Key ID: F631C7FD957D5F22

View File

@ -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;
}
}