Files
xLog/app/lib/upload.client.ts
T
2022-05-02 20:43:47 +08:00

16 lines
409 B
TypeScript

export const uploadFileInBrowser = async (blob: Blob) => {
const form = new FormData()
form.append("file", blob)
form.append("type", "image")
const res = await fetch(`/api/upload`, {
credentials: "same-origin",
body: form,
method: "POST",
})
if (!res.ok) {
throw new Error(`Upload failed: ${res.statusText}`)
}
const json = await res.json()
return json as { file: string }
}