Skip to content

Instantly share code, notes, and snippets.

@freeatnet
Created August 8, 2023 10:05
Show Gist options
  • Save freeatnet/6fa5047f6ed4454c504d3cf38b0cb99c to your computer and use it in GitHub Desktop.
Save freeatnet/6fa5047f6ed4454c504d3cf38b0cb99c to your computer and use it in GitHub Desktop.
const busboy = Busboy({ headers: req.headers });
busboy.on<"file">("file", function (name, stream, info) {
console.log("File [" + name + "]: filename: " + JSON.stringify(info));
stream.on("data", function (data) {
invariant(Buffer.isBuffer(data), "data is not a buffer");
console.log(data);
console.log(
"File [" + name + "] got " + data.length + typeof data + " bytes"
);
});
stream.on("end", function () {
console.log("File [" + name + "] Finished");
});
});
busboy.on<"field">("field", function (name, value) {
console.log("Field [" + name + "]: value: " + value);
});
busboy.on("finish", function () {
console.log("Done parsing form!");
res.writeHead(303, { Connection: "close", Location: "/" });
res.end();
});
req.pipe(busboy);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment