title: Storing a image in mongodb
body: <p>I'm trying to store images in mongo after downloading it with <a href="https://github.com/mikeal/request" rel="nofollow">request</a></p>
  
  <p>here is my code which causes a corrupted image to be stored in db.</p>
  
  <pre><code>request('http://test.jpg', function (error, response, image) {
  
      db.images.insert(
  
          {
              file_name: 'test.jpg',
              image: new Buffer(image)
          },
  
          function(err){
  
             //mongojs callback
  
          }
      );
  });
  </code></pre>
  
  <p>Please note I am using <a href="https://github.com/gett/mongojs" rel="nofollow">mongojs</a> module and storing the images in regular document as BinData type. </p>
  
  <p>Also if I write the image to a file, read it then save the image to the database then there is no corruption. But I don't want to do this as is my intention to avoid the file-system altogether.</p>
  
  <p>I'm pretty this has something to do with encoding or buffers but I don't know enough about these to solve my problem.</p>