From 04e11c3fedcd7da21ae746d71cc018adac16bd62 Mon Sep 17 00:00:00 2001 From: egecankomur Date: Tue, 12 May 2026 05:14:37 +0300 Subject: [PATCH] fix: normalize image filename extension before Appwrite upload --- src/app/api/properties/images/route.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/app/api/properties/images/route.ts b/src/app/api/properties/images/route.ts index b005cc9..b5be815 100644 --- a/src/app/api/properties/images/route.ts +++ b/src/app/api/properties/images/route.ts @@ -39,7 +39,17 @@ export async function POST(request: NextRequest) { try { const buffer = Buffer.from(await file.arrayBuffer()); - const inputFile = InputFile.fromBuffer(buffer, file.name); + const extMap: Record = { + "image/jpeg": ".jpg", + "image/png": ".png", + "image/webp": ".webp", + "image/gif": ".gif", + "image/avif": ".avif", + }; + const ext = extMap[file.type] ?? ".jpg"; + const baseName = file.name.replace(/\.[^/.]+$/, ""); + const safeName = baseName + ext; + const inputFile = InputFile.fromBuffer(buffer, safeName); const created = await storage.createFile( BUCKETS.propertyImages,