title: Creating a BLOB from a Base64 string in JavaScript
body: <p>I have Base64-encoded binary data in a string:</p>
  
  <pre class="lang-javascript prettyprint-override"><code>const contentType = 'image/png';
  const b64Data = 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
  </code></pre>
  
  <p>I would like to create a <code>blob:</code> URL containing this data and display it to the user:</p>
  
  <pre class="lang-javascript prettyprint-override"><code>const blob = new Blob(????, {type: contentType});
  const blobUrl = URL.createObjectURL(blob);
  
  window.location = blobUrl;
  </code></pre>
  
  <p>I haven't been been able to figure out how to create the BLOB.</p>
  
  <p>In some cases I am able to avoid this by using a <code>data:</code> URL instead:</p>
  
  <pre class="lang-javascript prettyprint-override"><code>const dataUrl = `data:${contentType};base64,${b64Data}`;
  
  window.location = dataUrl;
  </code></pre>
  
  <p>However, in most cases the <code>data:</code> URLs are prohibitively large.</p>
  
  <hr>
  
  <p>How can I decode a Base64 string to a BLOB object in JavaScript?</p>