title: Express JS Save image on server
body: <p>I am sending image from my iPhone App to server. Restful API is in express JS. 
  I am getting image on server using POST request. I am able to print the binary data but not able to store it properly. When I open the image from specified location,its corrupted. Here is my express js code. </p>
  
  <pre><code>app.post('/api/pictures',function(req,res){
  console.log(req.headers);
      var body = '';
      filePath = 'C:/Users/Desktop/restful/image.png';
      req.on('data', function(data) {
      console.log(data);
      body += data;
  });
  
   req.on('end', function (){ 
       fs.appendFile(filePath, body, function() { 
       res.end(); 
       });
     });
    res.send("Success!");
  });
  </code></pre>
  
  <p>My req.headers is</p>
  
  <p><img src="https://i.stack.imgur.com/dQqzT.jpg" alt="enter image description here"></p>
  
  <p>Am I doing anything wrong?</p>
  
  <p>Where as I am getting this response on client side </p>
  
  <pre><code>{ status code: 200, headers {
  Connection = "keep-alive";
  "Content-Length" = 8;
  "Content-Type" = "text/html; charset=utf-8";
  Date = "Wed, 14 Jan 2015 16:15:01 GMT";
  "X-Powered-By" = Express;
   } }
  upload completed, response: Optional(Success!)
  </code></pre>
  
  <p>Thanks in advance. </p>