import { NextResponse } from "next/server"; import fs from "node:fs/promises"; import path from "path"; export async function POST(req) { try { // Parse the form data const formData = await req.formData(); const file = formData.get("file"); const arrayBuffer = await file.arrayBuffer(); const buffer = new Uint8Array(arrayBuffer); // Define the destination path const destinationDir = "/var/lib/tftpboot/"; const filePath = path.join(destinationDir, file.name); // Write the file to the destination await fs.writeFile(filePath, buffer); return NextResponse.json({ status: "success", filePath }); } catch (e) { console.error(e); return NextResponse.json({ status: "fail", error: e.message }, { status: 500 }); } }