fix: normalize image filename extension before Appwrite upload
This commit is contained in:
@@ -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<string, string> = {
|
||||
"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,
|
||||
|
||||
Reference in New Issue
Block a user