1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

add web demo

This commit is contained in:
songjunxi
2023-10-23 09:02:56 +08:00
parent dbb5b1bdfb
commit bab0cf49a1
29 changed files with 6440 additions and 535 deletions

View File

@@ -0,0 +1,31 @@
import { put } from "@vercel/blob";
import { NextResponse } from "next/server";
export const runtime = "edge";
export async function POST(req: Request) {
if (!process.env.BLOB_READ_WRITE_TOKEN) {
return new Response(
"Missing BLOB_READ_WRITE_TOKEN. Don't forget to add that to your .env file.",
{
status: 401,
},
);
}
const file = req.body || "";
const filename = req.headers.get("x-vercel-filename") || "file.txt";
const contentType = req.headers.get("content-type") || "text/plain";
const fileType = `.${contentType.split("/")[1]}`;
// construct final filename based on content-type if not provided
const finalName = filename.includes(fileType)
? filename
: `${filename}${fileType}`;
const blob = await put(finalName, file, {
contentType,
access: "public",
});
return NextResponse.json(blob);
}