Skip to content

50+ open-source generative AI apps you can clone, deploy, and monetize — image generators, video tools, virtual try-ons, AI SaaS templates, and platform integrations. One-click Vercel deploy on every template.

Restore: src/app/api/upload/route.js

Anil Chandra Naidu Matchab11a5bc473d7
diff --git a/src/app/api/upload/route.js b/src/app/api/upload/route.js
new file mode 100644
index 0000000..7f76c18
--- /dev/null
+++ b/src/app/api/upload/route.js
@@ -0,0 +1,41 @@
+import { NextResponse } from "next/server";
+import config from "@/lib/config";
+
+export async function POST(req) {
+ try {
+ const data = await req.formData();
+ const file = data.get("file");
+ const apiKey = config.ai.apiKey;
+
+ if (!file) {
+ return NextResponse.json({ error: "No file provided" }, { status: 400 });
+ }
+
+ if (!apiKey || apiKey.includes("your_") || apiKey.trim() === "") {
+ // Local Base64 Fallback
+ const bytes = await file.arrayBuffer();
+ const buffer = Buffer.from(bytes);
+ return NextResponse.json({ url: `data:${file.type};base64,${buffer.toString("base64")}` });
+ }
+
+ const fd = new FormData();
+ fd.append("file", file);
+
+ const uploadRes = await fetch(config.ai.uploadEndpoint || "https://api.muapi.ai/api/v1/upload_file", {
+ method: "POST",
+ headers: { "x-api-key": apiKey },
+ body: fd
+ });
+
+ if (!uploadRes.ok) {
+ const errText = await uploadRes.text();
+ return NextResponse.json({ error: `Upload failed: ${errText}` }, { status: 500 });
+ }
+
+ const result = await uploadRes.json();
+ return NextResponse.json({ url: result.url || result.file_url });
+ } catch (error) {
+ console.error("[UPLOAD_ERROR]", error);
+ return NextResponse.json({ error: error.message || "Internal Upload Error" }, { status: 500 });
+ }
+}