Uploading binary file on Node.js Uploading binary file on Node.js express express

Uploading binary file on Node.js


Take out the following line

req.setEncoding('utf8');

You're not receiving utf8 data, you're receiving binary data.

You would be better off using a buffer instead of a string

app.use(function(req, res, next) {  var data = new Buffer('');  req.on('data', function(chunk) {      data = Buffer.concat([data, chunk]);  });  req.on('end', function() {    req.rawBody = data;    next();  });});