How to intercept multi-line file stream in Express.js?

Following the lead

https://github.com/visionmedia/express/blob/master/examples/multipart/app.js

Express.js seems to do all the work behind the scenes and save the file and transfer it in its entirety. How can I intercept and process the raw thread? In particular, I would like to receive a stream so that I can connect it to a recording stream.

+3
source share
2 answers

You cannot, unless you create middleware that uses the formidable and intercepts the stream there (the solution would be to change the bodyParser used by Express using a special one).

: https://github.com/senchalabs/connect/blob/master/lib/middleware/multipart.js

, "" , .

+3

:

app.use(express.multipart({ defer: true }));

:

app.post('/upload', function (request, response, next) {
  request.form.onPart = function (part) {
    // Default handling for non-files
    if (!part.filename) return form.handlePart(part);

    // part is a stream of the file
  };

  request.form.parse(request, function (error) {
    if (error) return next(error);
  });
});
0

All Articles