stevekrouse-compress_image_demo.web.val.run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/** @jsxImportSource npm:hono@3/jsx */
import { modifyImage } from "https://esm.town/v/stevekrouse/modifyImage";
import { Hono } from "npm:hono@3";
const app = new Hono();
app.get("/", (c) =>
c.html(
<form action="/" method="post" enctype="multipart/form-data">
<input type="file" accept="image/*" name="file">Upload photo</input>
<button type="submit">Submit</button>
</form>,
));
app.post("/", async (c) => {
const formData = await c.req.formData();
const file = formData.get("file") as File;
const compressed = await modifyImage(file, { width: 200, height: 200 });
return c.newResponse(compressed);
});
export default app.fetch;
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
April 18, 2024