• Actually I just dug this out of some personal code I had:

    function onPageRequest(req, res) {
      var header = "";
      req.on('data', function(d) { 
        header += d;
        var idx = header.indexOf("\r\n\r\n");
        if (idx>=0) {
          var f = E.openFile("f.txt", "w");
          f.write(header.substring(idx+4));
          header = undefined;
          req.removeAllListeners('data');
          req.pipe(f);
        }
      });
      res.writeHead(200, {'Content-Type': 'text/html'});
      res.write('<html><body><form method="post" enctype="multipart/form-data">');
      res.write('<input type="file" name="file" id="file"><input type="submit">');
      res.end('</form></body></html>');
    }
    require('http').createServer(onPageReque­st).listen(8080);
    

    It works fine - the only problem is that you end up with the HTTP 'boundary' on the end of the file - so if you care about that then it probably makes sense to handle it with on('data' instead and keep checking for the boundary (which is more painful than it sounds).

About

Avatar for Gordon @Gordon started