1

I'm writing a cli that PUTs data to a Meteor backend, which in turn uses express connect middleware. Any large file (over 700K) never finish uploading and the _req.on("end" event never fires.

Smaller files (under 700K) work fine however, and the _req.on("end" event always fires.

This is the cli client:

fs.readFile(file, function(err, data) {
    var req = http.request({
        method: 'PUT',
        host: 'localhost',
        path: '/api/deploy',
        port: '3000',
        timeout: 60 * 60 * 1000, // 1 hour
        headers : {
            "Content-Length" : data.length
        }
     },
     function(response) {
         console.log("done");
      }
    );
    req.write(data);
    req.end();
});

And here is the relevant server code:

this.route("deploy", {
    where: "server"
    , path: "/api/deploy"
    , action: function() {
        var _self = this;
        var _req = _self.request;
        var _total = _self.request.headers["content-length"];
        var _write = fs.createWriteStream("/tmp/test.tar");
        _req.pipe(_write);

        var _consumed = 0;

        _req.on("data", function(chunk) {
            _consumed += chunk.length;
                var uploadProgress = (_consumed/_total) * 100;
            console.log(uploadProgress);
        });

        _req.on("end", function() {
            console.log("ALL DONE");
        });
    }
});

I've tried adjusting the connect upload parameter in the bodyParser and elsewhere. If the default limit is 100mb, then I don't think this is the issue anyway.

Any help would be great. I am on OSX Mavericks. There is a hard limit set somewhere, I just don't know what it is, nor how to circumvent it.

TimDog
  • 8,280
  • 4
  • 38
  • 49
  • Have you tried uploading with something like `fs.createReadStream('test.png').pipe(request.post('http://127.0.0.1:3000/deploy'));` to upload the file in chunks too? What about if you tried uploading via the Chrome `Postman` plugin does it work (helps identify whether its client side or server side issue) – Tarang May 27 '14 at 05:48
  • Yep I have tried smaller files in `pipe`s and they all work well..i think i may try a vanilla node server (instead of meteor) to see if the problem persists... – TimDog May 27 '14 at 14:41
  • @I also noticed you're not using multipart/form-data which becomes an issue when the data is larger. I've used nearly the same code as yours (meteor side) which is why I suspect it may be the client side causing the issue – Tarang May 27 '14 at 14:44
  • Well, I'm curious what you were trying to set in the bodyParser, but it seems this is related to this: Request Entity Too Large http://stackoverflow.com/questions/19917401/node-js-express-request-entity-too-large – MrMowgli Feb 09 '15 at 08:22

0 Answers0