summaryrefslogtreecommitdiff
path: root/app/api/rfq-upload
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-03-25 15:55:45 +0900
committerjoonhoekim <26rote@gmail.com>2025-03-25 15:55:45 +0900
commit1a2241c40e10193c5ff7008a7b7b36cc1d855d96 (patch)
tree8a5587f10ca55b162d7e3254cb088b323a34c41b /app/api/rfq-upload
initial commit
Diffstat (limited to 'app/api/rfq-upload')
-rw-r--r--app/api/rfq-upload/route.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/api/rfq-upload/route.ts b/app/api/rfq-upload/route.ts
new file mode 100644
index 00000000..97beafb1
--- /dev/null
+++ b/app/api/rfq-upload/route.ts
@@ -0,0 +1,36 @@
+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 })
+ }
+} \ No newline at end of file