feat: add allowOther field to questions and update image upload to return data URIs

This commit is contained in:
2026-05-30 01:35:33 +07:00 Unverified
parent 114804749c
commit 6a36965e8b
10 changed files with 689 additions and 27 deletions
+4 -6
View File
@@ -36,14 +36,12 @@ export async function POST(req: Request) {
return NextResponse.json({ error: "Invalid image extension" }, { status: 400 });
}
const filename = `${crypto.randomUUID()}.${originalExt}`;
const uploadDir = path.join(process.cwd(), "public", "form");
await mkdir(uploadDir, { recursive: true });
const buffer = Buffer.from(await file.arrayBuffer());
await writeFile(path.join(uploadDir, filename), buffer);
const base64 = buffer.toString("base64");
const mimeType = file.type;
const dataUri = `data:${mimeType};base64,${base64}`;
return NextResponse.json({ url: `/form/${filename}` });
return NextResponse.json({ url: dataUri });
} catch (error: any) {
console.error("Upload error:", error);
return NextResponse.json({ error: error.message || "Internal server error" }, { status: 500 });