var reader = new FileReader();
reader.readAsDataURL(blob); 
reader.onloadend = function() {
  var base64data = reader.result;                
  console.log(base64data);
}

Form the docs readAsDataURL encodes to base64

As an awaitable function:

function blobToBase64(blob) {
  return new Promise((resolve, _) => {
    const reader = new FileReader();
    reader.onloadend = () => resolve(reader.result);
    reader.readAsDataURL(blob);
  });
}

Note: The blob's result cannot be directly decoded as Base64 without first removing the Data-URL declaration preceding the Base64-encoded data. To retrieve only the Base64 encoded string, first remove data:/;base64, from the result.

Answer from Arun Killu on Stack Overflow
🌐
Ionic
ionic.io › home › converting a base64 string to a blob in javascript
Converting a base64 string to a blob in JavaScript - Ionic Blog
August 27, 2020 - To save the photo permanently to the filesystem (blobs are objects temporarily loaded into browser memory), the Filesystem API requires the data to be in base64 format, so we must convert the blob into a base64 string.
Discussions

Creating a Blob from a base64 string in JavaScript - Stack Overflow
0 I have base64 stream of a pdf file. Now I need to convert it into a pdf file in Native Javascript. How can I do that? 0 How to send multiple byteIO files from Flask endpoint to Vue using axios and file encoding · 0 Encode a Blob with PHP and Decode with JavaScript through an AJAX request More on stackoverflow.com
🌐 stackoverflow.com
What is base64 blob storage?
Hi all, I am uploading my files to azure blob storage using Javascript. I am not converting it into base64 format. What is the advantages and disadvantages if I convert my files to base64 before uploading into azure blob containers? And I have few… More on learn.microsoft.com
🌐 learn.microsoft.com
2
0
July 20, 2021
How to convert glides image url into base 64 without Javascript/Make?
Every time a user uploads a picture we want to convert it to base64 for one of our integration partners. The Javascript column caches and therefore is too unreliable, while Make ends up being too costly having to also pay for a coding module partner (like 1001fx). More on community.glideapps.com
🌐 community.glideapps.com
3
0
November 26, 2024
Need to display huge PDFs from base64 string, but browser has limitations.
Try this https://stackoverflow.com/a/71075493 More on reddit.com
🌐 r/webdev
14
5
November 22, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-blob-to-base64-encoding-using-javascript
How to convert blob to base64 encoding using JavaScript ? - GeeksforGeeks
July 12, 2025 - <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Convert Blob to Base64 String</title> </head> <body> <div>Hello GeeksForGeeks</div> <script type="text/javascript"> let blob = new Blob(["GeeksForGeeks"], { type: "text/plain" }); // The full Blob Object can be seen // in the Console of the Browser console.log('Blob - ', blob); let reader = new FileReader(); reader.readAsDataURL(blob); reader.onloadend = function () { let base64String = reader.result; console.log('Base64 String - ', base64String); // Simply Print the Base64 Encoded String, // without additional data: Attributes.
🌐
GitHub
gist.github.com › n1ru4l › dc99062577b746e0783410b1298ab897
Fetch blob and convert to base64 · GitHub
Fetch blob and convert to base64 · Raw · index.js · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › FileReader › readAsDataURL
FileReader: readAsDataURL() method - Web APIs | MDN
September 18, 2025 - Note: The blob's result cannot be directly decoded as Base64 without first removing the Data-URL declaration preceding the Base64-encoded data.
🌐
Base64Encode.org
base64encode.org › enc › blob
Base64 Encoding of "blob" - Online
Enable this option to encode into an URL- and filename- friendly Base64 variant (RFC 4648 / Base64URL) where the "+" and "/" characters are respectively replaced by "-" and "_", as well as the padding "=" signs are omitted. Live mode: When you turn on this option the entered data is encoded immediately with your browser's built-in JavaScript functions, without sending any information to our servers.
Find elsewhere
🌐
Medium
geekjob.medium.com › convert-blob-to-base64-in-js-e5808fd69961
Convert Blob to Base64 in JS - Fullstack CTO - Medium
March 22, 2023 - const blob2base64 = (blob, mimeType) => { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onloadend = () => { const dataUrlPrefix = `data:${mimeType};base64,`; const base64WithDataUrlPrefix = reader.result; const base64 = base64WithDataUrlPrefix.replace(dataUrlPrefix, ''); resolve(base64); }; reader.onerror = reject; reader.readAsDataURL(blob); }); }; const obj = { hello: 'world' }; const mimeType = 'application/json'; const blob = new Blob([JSON.stringify(obj, null, 2)], { type: mimeType }); blob2base64(blob, mimeType).then(base64 => { console.log(base64); }); // or const base64 = await blob2base64(blob, mimeType); console.log(base64);
🌐
GitHub
gist.github.com › Miouyouyou › 32faf510f9cf13b1fd542bf8b7a8596b
Javascript blob to base64 · GitHub
Javascript blob to base64. GitHub Gist: instantly share code, notes, and snippets.
🌐
David Angulo
davidangulo.xyz › posts › convert-blob-to-base64-in-javascript
Convert Blob to base64 in JavaScript | David Angulo - Software Engineer
January 2, 2023 - readAsDataURL allows us to get the File or Blob’s data URI scheme which would contain our base64 string.
🌐
haikel-fazzani
haikel-fazzani.eu.org › home › javascript › convert blob to base64 and vice versa in javascript
Convert Blob to Base64 and Vice Versa in JavaScript
July 11, 2025 - Converting between Blob and Base64 in JavaScript is straightforward with the right tools, such as FileReader, btoa(), and atob(). Whether you’re embedding images in a webpage, sending files to an API, or processing binary data, these techniques ...
🌐
JavaScript.info
javascript.info › tutorial › binary data, files
Blob
An alternative to URL.createObjectURL is to convert a Blob into a base64-encoded string.
🌐
GitHub
gist.github.com › Jonarod › 77d8e3a15c5c1bb55fa9d057d12f95bd
Javascript utility to convert Blob to Base64, ImageData or ObjectUrl back and forth. Tree shakeable and promise based. · GitHub
Javascript utility to convert Blob to Base64, ImageData or ObjectUrl back and forth. Tree shakeable and promise based. - blob_conversions_util.js
Top answer
1 of 16
1181

The atob function will decode a base64-encoded string into a new string with a character for each byte of the binary data.

const byteCharacters = atob(b64Data);

Each character's code point (charCode) will be the value of the byte. We can create an array of byte values by applying this using the .charCodeAt method for each character in the string.

const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
    byteNumbers[i] = byteCharacters.charCodeAt(i);
}

You can convert this array of byte values into a real typed byte array by passing it to the Uint8Array constructor.

const byteArray = new Uint8Array(byteNumbers);

This in turn can be converted to a Blob by wrapping it in an array and passing it to the Blob constructor.

const blob = new Blob([byteArray], {type: contentType});

The code above works. However the performance can be improved a little by processing the byteCharacters in smaller slices, rather than all at once. In my rough testing 512 bytes seems to be a good slice size. This gives us the following function.

const b64toBlob = (b64Data, contentType='', sliceSize=512) => {
  const byteCharacters = atob(b64Data);
  const byteArrays = [];

  for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
    const slice = byteCharacters.slice(offset, offset + sliceSize);

    const byteNumbers = new Array(slice.length);
    for (let i = 0; i < slice.length; i++) {
      byteNumbers[i] = slice.charCodeAt(i);
    }

    const byteArray = new Uint8Array(byteNumbers);
    byteArrays.push(byteArray);
  }
    
  const blob = new Blob(byteArrays, {type: contentType});
  return blob;
}
const blob = b64toBlob(b64Data, contentType);
const blobUrl = URL.createObjectURL(blob);

window.location = blobUrl;

Full Example:

Show code snippet

const b64toBlob = (b64Data, contentType='', sliceSize=512) => {
  const byteCharacters = atob(b64Data);
  const byteArrays = [];

  for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
    const slice = byteCharacters.slice(offset, offset + sliceSize);

    const byteNumbers = new Array(slice.length);
    for (let i = 0; i < slice.length; i++) {
      byteNumbers[i] = slice.charCodeAt(i);
    }

    const byteArray = new Uint8Array(byteNumbers);
    byteArrays.push(byteArray);
  }
    
  const blob = new Blob(byteArrays, {type: contentType});
  return blob;
}

const contentType = 'image/png';
const b64Data = 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';

const blob = b64toBlob(b64Data, contentType);
const blobUrl = URL.createObjectURL(blob);

const img = document.createElement('img');
img.src = blobUrl;
document.body.appendChild(img);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

2 of 16
666

Here is a more minimal method without any dependencies or libraries.
It requires the new fetch API. (Can I use it?)

var url = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="

fetch(url)
.then(res => res.blob())
.then(console.log)
Run code snippetEdit code snippet Hide Results Copy to answer Expand

With this method you can also easily get a ReadableStream, ArrayBuffer, text, and JSON.
(fyi this also works with node-fetch in Node)

As a function:

const b64toBlob = (base64, type = 'application/octet-stream') => 
  fetch(`data:${type};base64,${base64}`).then(res => res.blob())

But I would encourage you to don't use base64 in the first place. There are better ways to send and receive binary data. JSON isn't always the best option. it takes up more bandwidth and waste processing time (de)encodeing stuff. Us eg canvas.toBlob instead of canvas.toDataURL and use FormData to send binary files. you can also return back a multipart payload and decode it using await response.formData() that is coming from a server response. FormData can go both ways.


I did a simple performance test towards Jeremy's ES6 sync version.
The sync version will block UI for a while. keeping the devtool open can slow the fetch performance

Show code snippet

document.body.innerHTML += '<input autofocus placeholder="try writing">'
// get some dummy gradient image
var img=function(){var a=document.createElement("canvas"),b=a.getContext("2d"),c=b.createLinearGradient(0,0,1500,1500);a.width=a.height=3000;c.addColorStop(0,"red");c.addColorStop(1,"blue");b.fillStyle=c;b.fillRect(0,0,a.width,a.height);return a.toDataURL()}();


async function perf() {
  
  const blob = await fetch(img).then(res => res.blob())
  // turn it to a dataURI
  const url = img
  const b64Data = url.split(',')[1]

  // Jeremy Banks solution
  const b64toBlob = (b64Data, contentType = '', sliceSize=512) => {
    const byteCharacters = atob(b64Data);
    const byteArrays = [];
    
    for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
      const slice = byteCharacters.slice(offset, offset + sliceSize);
      
      const byteNumbers = new Array(slice.length);
      for (let i = 0; i < slice.length; i++) {
        byteNumbers[i] = slice.charCodeAt(i);
      }
      
      const byteArray = new Uint8Array(byteNumbers);
      
      byteArrays.push(byteArray);
    }
    
    const blob = new Blob(byteArrays, {type: contentType});
    return blob;
  }

  // bench blocking method
  let i = 500
  console.time('blocking b64')
  while (i--) {
    await b64toBlob(b64Data)
  }
  console.timeEnd('blocking b64')
  
  // bench non blocking
  i = 500

  // so that the function is not reconstructed each time
  const toBlob = res => res.blob()
  console.time('fetch')
  while (i--) {
    await fetch(url).then(toBlob)
  }
  console.timeEnd('fetch')
  console.log('done')
}

perf()
Run code snippetEdit code snippet Hide Results Copy to answer Expand

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-base64-to-blob-in-javascript
How to Convert Base64 to Blob in JavaScript? - GeeksforGeeks
September 4, 2024 - In this approach, we are going to decode a Base64-encoded image string into a binary format, convert it into a 'Blob', and create a downloadable file from it. The Base64 string is first split and decoded into binary data, which is then chunked ...
🌐
Saturn Cloud
saturncloud.io › blog › creating-a-blob-from-a-base64-string-in-javascript
Creating a BLOB from a Base64 string in JavaScript | Saturn Cloud Blog
May 1, 2026 - Specify Content Type: When creating a BLOB, always specify the content type using the Blob constructor. This helps browsers interpret the data correctly. Handle Asynchronous Operations: If decoding or processing the Base64 string involves asynchronous operations, ensure proper error handling and use async/await or Promises. Cross-Browser Compatibility: Test your code across different browsers to ensure compatibility. Different browsers may have variations in their implementation of JavaScript functions.
🌐
GitHub
gist.github.com › fupslot › 5015897
Javascript: Convert base64 to a Blob · GitHub
Thanks so much :) Tremendous help for me using Expo Image Picker and uploading to Google Storage. ... function dataURIToBlob(dataURI: string) { dataURI = dataURI.replace(/^data:/, ''); const type = dataURI.match(/image\/[^;]+/)[0]; const base64 = dataURI.replace(/^[^,]+,/, ''); const arrayBuffer = new ArrayBuffer(base64.length); const typedArray = new Uint8Array(arrayBuffer); for (let i = 0; i < base64.length; i++) { typedArray[i] = base64.charCodeAt(i); } return new Blob([arrayBuffer], { type }); }
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 483762 › what-is-base64-blob-storage
What is base64 blob storage? - Microsoft Q&A
July 20, 2021 - Specifying the version number of the SDK will be necessary. However, the storage SDKs generally do not alter the blob content being uploaded in any way. Base 64 takes more space than whatever bytes you converted and it takes linear time to convert bytes to a base64 string.
🌐
Glide Community
community.glideapps.com › ask for help
How to convert glides image url into base 64 without Javascript/Make? - Ask for Help - Glide Community
November 26, 2024 - Every time a user uploads a picture we want to convert it to base64 for one of our integration partners. The Javascript column caches and therefore is too unreliable, while Make ends up being too costly having to also p…
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Blob
Blob - Web APIs | MDN
3 weeks ago - The Blob interface represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a ReadableStream so its methods can be used for processing the data.