title: Base64 encoding uploaded images using Node JS
body: <p>What is the simplest way to encode PNG images to base64 using NodeJS? I need to store the presentation as a string in mongodb. The UI posts a mulitpart form and I can see the content being post correctly over the wire i.e;</p>
  
  <pre><code>Content-Disposition: form-data; name="userFile"; filename="Untitled2.png" Content-Type: image/png
  Content-Type    multipart/form-data; boundary=---------------------------71011331421746
  </code></pre>
  
  <p>Need to iterate through a file list and encode each file. </p>
  
  <pre><code>app.post('/api/upload', function (req, res) {    
  
      var thumbnails = [].concat(req.files.thumbnail);
  
       for (var x = 0; x &lt; thumbnails.length; x++) {
          taskItem.push({bin: new Buffer(thumbnails[x]).toString('base64')});
       }
  }
  </code></pre>
  
  <p>Any help is appreciated.</p>
  
  <p>J</p>