Spaces:
Runtime error
Runtime error
Download src/app/api/upload/route.ts from RalphThings/yue2-studio: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/RalphThings/yue2-studio/resolve/main/src/app/api/upload/route.ts
- Command line
-
hf download hf://spaces/RalphThings/yue2-studio/src/app/api/upload/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/RalphThings/yue2-studio/resolve/main/src/app/api/upload/route.ts
1.01 kB
| import { NextResponse } from "next/server"; | |
| import { IS_MOCK, uploadAudio } from "@/lib/comfy/client"; | |
| export const runtime = "nodejs"; | |
| export const dynamic = "force-dynamic"; | |
| const MAX_BYTES = 120 * 1024 * 1024; | |
| export async function POST(request: Request) { | |
| const form = await request.formData().catch(() => null); | |
| const file = form?.get("file"); | |
| if (!(file instanceof File)) { | |
| return NextResponse.json({ error: "No file in the request" }, { status: 400 }); | |
| } | |
| if (file.size > MAX_BYTES) { | |
| return NextResponse.json({ error: "That file is larger than 120 MB" }, { status: 413 }); | |
| } | |
| if (IS_MOCK) { | |
| return NextResponse.json({ filename: file.name, name: file.name, size: file.size }); | |
| } | |
| try { | |
| const filename = await uploadAudio(file); | |
| return NextResponse.json({ filename, name: file.name, size: file.size }); | |
| } catch (error) { | |
| return NextResponse.json( | |
| { error: error instanceof Error ? error.message : "Upload failed" }, | |
| { status: 502 }, | |
| ); | |
| } | |
| } | |