c4urself
c4urself

Reputation: 4287

How can I pipe a file without having buffer build up in Node.JS?

I'm using Node.JS to proxy a file upload to a remote endpoint and need to make sure my Node server doesn't buffer the file excessively.

I'm using res.write to push in the following way:

apiRes.on('data', function (chunk) {
    body += chunk;
    res.write(chunk);
});

(The connection is faster from client to node than from node to the remote).

Note that the client is a browser, if that wasn't clear.

Upvotes: 2

Views: 634

Answers (2)

pdvyas
pdvyas

Reputation: 76

  • use xhr.send file with the help of FileReader.
  • use apiRes.pipe(res) as suggested by Dream707

Upvotes: 2

Yury Solovyov
Yury Solovyov

Reputation: 515

Node.js API Docs

apiRes.pipe(res);

Upvotes: 3

Related Questions