diff options
author | 2022-10-13 02:27:54 -0700 | |
---|---|---|
committer | 2022-10-13 02:27:54 -0700 | |
commit | b0a7f8df926e91d3b2f0b3b8833ddaf55073f30e (patch) | |
tree | b363b5670b6a631e4adc383a71a064f1f51ee164 /examples | |
parent | 32e16bda23976cfb4efc06ce779fcf99604b1b3f (diff) | |
download | bun-b0a7f8df926e91d3b2f0b3b8833ddaf55073f30e.tar.gz bun-b0a7f8df926e91d3b2f0b3b8833ddaf55073f30e.tar.zst bun-b0a7f8df926e91d3b2f0b3b8833ddaf55073f30e.zip |
Create http-request-body.ts
Diffstat (limited to 'examples')
-rw-r--r-- | examples/http-request-body.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/http-request-body.ts b/examples/http-request-body.ts new file mode 100644 index 000000000..6ce356ce0 --- /dev/null +++ b/examples/http-request-body.ts @@ -0,0 +1,16 @@ +import { serve } from "bun"; + +serve({ + async fetch(req) { + // body is a ReadableStream + const body = req.body; + + const writer = Bun.file(`upload.${Date.now()}.txt`).writer(); + for await (const chunk of body) { + writer.write(chunk); + } + const wrote = await writer.end(); + + return Response.json({ wrote, type: req.headers.get("Content-Type") }); + }, +}); |