title: JavaScript: Decode base64 into binary data
body: <p>I'm trying to create a image from a video by using a canvas and then sending the image to an API.</p>
  
  <p>This is my code (large parts are omitted for brevity)   </p>
  
  <pre><code>      var image = new Image();
          image.src = canvas.toDataURL("image/png");
  
        var newFile = new File([atob(image.src)], lorem.png, {
           type: "image/png",
            lastModified: Date.now()
           })
  </code></pre>
  
  <p>image.src is a long string that seems to be in the format base64 data:image/png;base64</p>
  
  <p>[Link to the data ][1]:<a href="https://gist.github.com/anonymous/d357e780fa60b2c47490a9f795e34acf" rel="nofollow noreferrer">https://gist.github.com/anonymous/d357e780fa60b2c47490a9f795e34acf</a></p>
  
  <p>When I try to decode the data into binary with the function <em>atob</em>, I get the following error:</p>
  
  <blockquote>
    <p>Error: Failed to execute 'atob' on 'Window': The string to be decoded
    is not correctly encoded.</p>
  </blockquote>
  
  <p>It's not clear to me which part of the base64 data are not formatted correctly. </p>