You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
834 B
27 lines
834 B
3 months ago
|
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 });
|
||
|
}
|
||
|
}
|