Extracting Binary Data (a jpeg image) in the Request Body Sent to a Node.js Server Extracting Binary Data (a jpeg image) in the Request Body Sent to a Node.js Server express express

Extracting Binary Data (a jpeg image) in the Request Body Sent to a Node.js Server


This should do it:

var http = require('http');var fs = require('fs');var app = http.createServer(function (req, res) {  req.pipe(fs.createWriteStream(__dirname + req.url));  res.writeHead(200, {'Content-Type': 'text/plain'});  res.end('OK!');});app.listen(3000);

Verified with curl:

curl -H 'Content-Type: application/octet-stream' --data-binary @file.jpg localhost:3000/foo.jpg

If this doesn't work, I'd test it with curl to make sure it's not the client which is doing something weird.

When it comes to sending it over socket.io, I wouldn't do that, but send the URL instead. If that's not an option I guess you would have to base64 encode the data.