We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bce9e19 commit ef92daeCopy full SHA for ef92dae
src/app/api/ai-upload/route.ts
@@ -39,12 +39,15 @@ export async function POST(req: Request) {
39
const formData = await req.formData();
40
const files: File[] = formData.getAll("files") as File[];
41
const isPdf = formData.get("isPdf") === "true"; // Convert string to boolean
42
-
+
43
+ const orderedFiles = Array.from(files).sort((a, b) => {
44
+ return a.name.localeCompare(b.name);
45
+ });
46
let imageURL = "";
47
if (isPdf) {
48
imageURL = formData.get("image") as string;
49
} else {
- const bytes = await files[0]?.arrayBuffer();
50
+ const bytes = await orderedFiles[0]?.arrayBuffer();
51
if (bytes) {
52
const buffer = Buffer.from(bytes);
53
imageURL = `data:${"image/png"};base64,${buffer.toString("base64")}`;
0 commit comments