mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
17 lines
380 B
TypeScript
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") });
|
|
},
|
|
});
|