Skip to content

Commit

Permalink
add file upload example
Browse files Browse the repository at this point in the history
  • Loading branch information
zhmushan committed Jan 24, 2021
1 parent ef6e324 commit b27bf15
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/file_upload/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Usage

```
deno run --allow-net ./main.ts
# in another terminal
curl http://localhost:8080/file -F "file=@./file"
```
1 change: 1 addition & 0 deletions examples/file_upload/file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
17 changes: 17 additions & 0 deletions examples/file_upload/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { FormFile } from "../../vendor/https/deno.land/std/mime/multipart.ts";
import { Application } from "../../mod.ts";
import { decoder } from "../../vendor/https/deno.land/std/encoding/utf8.ts";

const app = new Application();

app.start({ port: 8080 });

console.log(`server listening on http://localhost:8080`);

app.post("/file", async (c) => {
const { file } = await c.body as { file: FormFile };
return {
name: file.filename,
content: decoder.decode(file.content),
};
});

0 comments on commit b27bf15

Please sign in to comment.