title: window.atob fails to decode string and throws an error
body: <pre><code>        function saveIMG(image) {
              var startIndex = image.indexOf("base64,") + 7;
              var b64 = image.substr(startIndex, image.indexOf("&gt;") - startIndex - 2);
              var byteCharacters = atob(b64);
              var byteNumbers = new Array(byteCharacters.length);
              for (var i = 0; i &lt; byteCharacters.length; i++) {
                  byteNumbers[i] = byteCharacters.charCodeAt(i);
              }
              var byteArray = new Uint8Array(byteNumbers);
              var data = new Blob([byteArray], {type: 'image/jpeg'});
              return "&lt;img src='" + window.URL.createObjectURL(data) + "' width='150'/&gt;";
          }
  </code></pre>
  
  <p>I wanted to use this code to encode a base64 image into an image with uses a URL. However, on the line where it uses <code>atob</code> it throws this error:</p>
  
  <blockquote>
    <p>Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.</p>
  </blockquote>
  
  <p>I can only assume it is something to do with the base64, or perhaps it cannot convert base64 images using <code>atob</code>. Anyhow, here is the start of the base64 that was taken from the substring:</p>
  
  <p><code>/9j/4AAQSkZJRgABAQEASABIAAD/7RTuUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAA8cAVoAAxslRxwCAAACAAAAOEJJTQQlAAAAAAAQzc/6fajHvgkFcHaurwXDTjhCSU0EOgAAAAAA5QAAABAAAAABAAAAAAALcHJpbnRPdXRwdXQAAAAFAAAAAFBzdFNib29sAQAAAABJbnRlZW51bQAAAABJbnRlAAAAAENscm0AAAAPcHJpbnRTaXh0ZWVuQml0Ym9vbAAA</code></p>