Created
January 2, 2020 11:37
-
-
Save SergeiMeza/c58856c423868a3098a61ad5692d71ee to your computer and use it in GitHub Desktop.
express receive file stream post request
This file contains hidden or 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
| import fs from "fs" | |
| import express from "express" | |
| app.post("/test-upload", async (req, res) => { | |
| const mimetype = req.headers["content-type"] | |
| const filename = req.headers["filename"] | |
| prettyPrint({ mimetype, filename }) | |
| if (!mimetype || typeof mimetype !== "string") return res.status(403).send() | |
| if (!filename || typeof filename !== "string") return res.status(403).send() | |
| req.pipe(fs.createWriteStream(__dirname + "/uploads/" + filename)) | |
| req.on("error", () => { | |
| return res.send({ success: false }) | |
| }) | |
| req.on("end", () => { | |
| return res.send({ success: true }) | |
| }) | |
| }) | |
| app.listen({ port: 4000 }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment