Working s3 compatible file uplaods!

This commit is contained in:
2026-03-30 14:28:44 -04:00
parent 6152dcdeea
commit 830ee36f84
16 changed files with 664 additions and 15 deletions

29
assets/js/upload.ts Normal file
View File

@@ -0,0 +1,29 @@
export interface UploadResult {
success: true;
mediaId: string;
url: string;
}
export interface UploadError {
success?: false;
error: string;
}
export async function uploadFile(
file: File,
csrfToken: string
): Promise<UploadResult | UploadError> {
const formData = new FormData();
formData.append("file", file);
// Do NOT set Content-Type — browser sets the multipart boundary automatically
const res = await fetch("/upload", {
method: "POST",
headers: { "X-CSRF-Token": csrfToken },
body: formData,
});
const json = await res.json();
if (!res.ok || !json.success) {
return { error: json.error ?? "Upload failed" };
}
return json as UploadResult;
}