Created
October 6, 2016 17:16
-
-
Save rmacfie/0d972ae6c0d1a46cbf627d46456c3a00 to your computer and use it in GitHub Desktop.
Convert application/octet-stream upload to ReadableStream
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 * as stream from "stream"; | |
import * as express from "express"; | |
import * as bodyParser from "body-parser"; | |
const app = express(); | |
app.use(bodyParser.raw()); | |
app.use(bodyParser.json()); | |
app.post("/upload", (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
const buffer = <Buffer>(<any>req).body; | |
const passthroughStream = new stream.PassThrough(); | |
passthroughStream.end(buffer); | |
// passthroughStream == readable stream with uploaded file data | |
return res.send("Thanks"); | |
}); | |
app.listen(5000, () => { | |
console.log("## Listening..."); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment