Skip to content

Instantly share code, notes, and snippets.

@rmacfie
Created October 6, 2016 17:16
Show Gist options
  • Save rmacfie/0d972ae6c0d1a46cbf627d46456c3a00 to your computer and use it in GitHub Desktop.
Save rmacfie/0d972ae6c0d1a46cbf627d46456c3a00 to your computer and use it in GitHub Desktop.
Convert application/octet-stream upload to ReadableStream
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