fix: allow larger file uploads
This commit is contained in:
@@ -5,17 +5,16 @@ import { error, type RequestHandler } from "@sveltejs/kit";
|
||||
|
||||
export const POST: RequestHandler = async ({ request }) => {
|
||||
const supabase = createClient<Database>(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY);
|
||||
const body = await request.json();
|
||||
const title = body.title;
|
||||
const imgB64 = body.img;
|
||||
const imgTitle = body.imgTitle;
|
||||
if (!title || !imgB64 || !imgTitle) error(400, "Missing required fields: title, img, imgTitle");
|
||||
const body = await request.bytes();
|
||||
const url = new URL(request.url);
|
||||
const title = url.searchParams.get("title");
|
||||
const imgTitle = url.searchParams.get("imgTitle");
|
||||
if (!title || !imgTitle) error(400, "Missing required fields: title, imgTitle");
|
||||
|
||||
const img = await fetch(imgB64).then((res) => res.blob());
|
||||
const { data: imageData, error: imageError } = await supabase.storage
|
||||
.from("files_bucket")
|
||||
.upload(`public/${imgTitle}`, img, {
|
||||
contentType: img.type,
|
||||
.upload(`public/${imgTitle}`, body, {
|
||||
contentType: request.headers.get("content-type") || "image/png",
|
||||
upsert: false
|
||||
});
|
||||
if (imageError) error(500, `Failed to upload image: ${imageError.message}`);
|
||||
|
||||
Reference in New Issue
Block a user