title: Convert S3 byte array to base64
body: <p>On my NodeJS server I download an image that I need to embed in an email. My bucket is NOT public so just using the link will not work, as is not the solution I want for the requirements of either this question or the project.</p>
  
  <p>I'm using a HTML email for this with something like:</p>
  
  <pre><code>&lt;p&gt;Embedded image: &lt;img src="data:image/jpeg;charset=utf-8;base64,{{url}}" /&gt;&lt;/p&gt;
  </code></pre>
  
  <p>So I download from S3</p>
  
  <pre><code>s3.getObject(
                            { Bucket: "mybucket", Key: "mykey" },
                            function (error, data) {
                              if (error != null) {
                                console.log("Errror" + error)
                              } else {
                                console.log("Loaded " + data.ContentLength + " bytes")
  </code></pre>
  
  <p>and then I'm trying to convert data.body to UTF-8 base 64</p>
  
  <p>I thought something like</p>
  
  <pre><code>"data:image/png;base64," + new String(encoder.encode(data.body), "UTF-8")
  </code></pre>
  
  <p>But it doesn't seem to work, and I'm struggling to define encoder to be able to do this.</p>