Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Lets see, where to begin:</p> <ul> <li>Yes, the request is a ReadStream that will emit <code>data</code> events as you said.</li> <li>The first chunk of data in the stream is stored in memory, there are no temporary files.</li> </ul> <p>The general issue you are running into is that you need to capture the data emitted from the <code>req</code> and re-emit it once the authentication is completed. Connect provides helpers to do this for you. It looks like passport-http doesn't currently use them.</p> <p>If you install the <a href="https://github.com/visionmedia/node-pause" rel="nofollow">pause</a> module it can handle this for you.</p> <p>Try something like this:</p> <pre><code>var pause = require('pause'); // Create our own middleware constructor. var bufferedAuthenticate = function(){ // Set up standard authenticate handler passing arguments through. var authMiddleware = passport.authenticate.apply(passport, arguments); // Pass our own middleware instead that wraps passport-http. return function(req, res, next){ // Pause the request before authenticating. var obj = pause(req); authMiddleware(req, res, function(err){ next(err); // Emit any cached data events that fired while authenticating. obj.resume(); }); }; }; app.post('/upload', bufferedAuthenticate('basic', { session: false }), function(req, res, next) { var dataLength = 0; req.on('data', function(chunk) { console.log('loading'); dataLength += chunk.length; }).on('end', function() { console.log('load end'); console.log('contentLength: %s', req.headers['content-length']); console.log('dataLength: : %s', dataLength); res.send(200); }); } ); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload