// app/api/file/upload/route.ts import { cookies } from 'next/headers'; import type { NextRequest } from 'next/server'; import { NextResponse } from 'next/server'; export async function POST(request: NextRequest) { try { // Get FormData from request const formData = await request.formData(); // Get auth token from cookies const cookieStore = await cookies(); const token = cookieStore.get('auth_token')?.value; if (!token) { return NextResponse.json( { message: 'Not authenticated' }, { status: 401 } ); } // Forward the FormData to external API const response = await fetch( 'https://byteriot-candidateexplorer.hf.space/CandidateExplorer/file/upload', { method: 'POST', headers: { Authorization: `Bearer ${token}`, // Don't set Content-Type, let fetch handle it for FormData }, body: formData, // Pass FormData directly } ); if (!response.ok) { const errorData = await response.json().catch(() => null); return NextResponse.json( { message: errorData?.message || 'Upload failed', error: errorData }, { status: response.status } ); } // Get response data from external API const data = await response.json(); return NextResponse.json( { success: true, message: 'Files uploaded successfully', data: data }, { status: 200 } ); } catch (error) { console.error('Upload CV error:', error); return NextResponse.json( { message: 'Failed to upload files', error: String(error) }, { status: 500 } ); } }