file uploader

This commit is contained in:
2023-10-05 10:27:52 -06:00
parent 6e582e11dc
commit 5779cd9efc
17 changed files with 847 additions and 37 deletions

21
routes/upload.ts Normal file
View File

@@ -0,0 +1,21 @@
import { Handlers } from "$fresh/server.ts";
import { ensureFile } from "$std/fs/ensure_file.ts";
export const handler: Handlers = {
async POST(req, _ctx) {
const path = req.headers.get("x-grizz-path");
if (!path) return new Response("Upload path not included", { status: 400 });
const files = Array.from((await req.formData()).values()) as File[];
for (const file of files) {
const filePath = path.replace(/.$/, (e) => e.replace("/", "") + "/") +
file.name;
await ensureFile(filePath);
const newFile = await Deno.open(filePath, { write: true });
file.stream().pipeTo(newFile.writable);
}
return new Response("Success");
},
};