This commit is contained in:
2026-04-19 17:23:31 +03:00
parent 9cad199125
commit 4f2188363a
122 changed files with 3215 additions and 116 deletions

33
app/api/upload/route.ts Normal file
View File

@@ -0,0 +1,33 @@
import { NextRequest, NextResponse } from 'next/server';
import cloudinary from '@/lib/cloudinary';
export async function POST(request: NextRequest) {
try {
const formData = await request.formData();
const file = formData.get('file') as File;
if (!file) {
return NextResponse.json({ error: 'No file provided' }, { status: 400 });
}
// Convert file to base64
const arrayBuffer = await file.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
const base64File = `data:${file.type};base64,${buffer.toString('base64')}`;
// Upload to Cloudinary
const result = await cloudinary.uploader.upload(base64File, {
folder: 'ayris-apart', // Organize images in a specific folder
resource_type: 'auto',
});
return NextResponse.json({
url: result.secure_url,
public_id: result.public_id,
});
} catch (error: any) {
console.error('Upload Error:', error);
return NextResponse.json({ error: error.message }, { status: 500 });
}
}