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