Skip to content

Commit ef92dae

Browse files
did based on file name
1 parent bce9e19 commit ef92dae

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/app/api/ai-upload/route.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ export async function POST(req: Request) {
3939
const formData = await req.formData();
4040
const files: File[] = formData.getAll("files") as File[];
4141
const isPdf = formData.get("isPdf") === "true"; // Convert string to boolean
42-
42+
43+
const orderedFiles = Array.from(files).sort((a, b) => {
44+
return a.name.localeCompare(b.name);
45+
});
4346
let imageURL = "";
4447
if (isPdf) {
4548
imageURL = formData.get("image") as string;
4649
} else {
47-
const bytes = await files[0]?.arrayBuffer();
50+
const bytes = await orderedFiles[0]?.arrayBuffer();
4851
if (bytes) {
4952
const buffer = Buffer.from(bytes);
5053
imageURL = `data:${"image/png"};base64,${buffer.toString("base64")}`;

0 commit comments

Comments
 (0)