Created
August 8, 2023 10:05
-
-
Save freeatnet/6fa5047f6ed4454c504d3cf38b0cb99c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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