Hi, I'm trying to upload file and handle it with Fresh, and i don't know how to get file content and save it into a file on the server.
Do any have code snippets ?
My code atm :
/api/file
import {Handlers} from "$fresh/server.ts";
export const handler: Handlers = {
async POST(req, ctx) {
const data = await req.formData();
console.log(data.get("file");
return new Response("OK");
},
};
// output : <file-name.ext>
import { Head } from "$fresh/runtime.ts";
export default function Home() {
return (
<>
<Head>
<title>Fresh App</title>
</Head>
<div class="p-4 mx-auto max-w-screen-md">
<form action="/api/file" method="POST">
<input type="file" name="file" />
<input type="submit" value="Upload" />
</form>
</div>
</>
);
}