Files
bun.sh/examples/http-request-body.ts
2022-10-13 02:27:54 -07:00

17 lines
380 B
TypeScript

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") });
},
});