import { NextRequest, NextResponse } from "next/server" import { promises as fs } from "fs" import path from "path" import { v4 as uuidv4 } from "uuid" export async function POST(req: NextRequest) { try { const formData = await req.formData() const file = formData.get("file") as File // "file" is default name from FilePond if (!file) { return NextResponse.json({ error: "No file" }, { status: 400 }) } // e.g. parse a query param? or read 'rfqId' if we appended it // const rfqId = ... (FilePond advanced config or handle differently) // read file const arrayBuffer = await file.arrayBuffer() const buffer = Buffer.from(arrayBuffer) // unique filename const uniqueName = uuidv4() + "-" + file.name const targetDir = path.join(process.cwd(), "public", "rfq", "123") // or your rfqId await fs.mkdir(targetDir, { recursive: true }) const targetPath = path.join(targetDir, uniqueName) // write await fs.writeFile(targetPath, buffer) // Return success. Typically you'd insert DB record here or return some reference return NextResponse.json({ success: true, filePath: `/rfq/123/${uniqueName}` }) } catch (error) { console.error("upload error:", error) return NextResponse.json({ error: String(error) }, { status: 500 }) } }