diff options
Diffstat (limited to 'examples/http-request-body.ts')
-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") }); + }, +}); |