You can convert your Base64 string to Buffer and then try storing it to azure.

var base64String = "....."; // your base64 string
var bufferValue = Buffer.from(base64String,"base64");
Answer from Ahsan Jamal on Stack Overflow
🌐
npm
npmjs.com › package › b64-to-blob
b64-to-blob - npm
`b64toBlob(b64Data: string, contentType?: string): Blob` converts a base64 string to a Blob object [as described in this Stack Overflow post](https://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript)..
      » npm install b64-to-blob
    
Published: Aug 21, 2017
Version: 1.2.19
🌐
npm
npmjs.com › package › base64-blob
base64-blob - npm
July 23, 2019 - skip to:contentpackage searchsign ... means that you can apply tree-shaking in you project · A module for interconversion of base64 and blob, wrapped by Promise ·...
      » npm install base64-blob
    
Published: Jul 23, 2019
Version: 1.4.1
      » npm install base64toblob
    
Published: May 22, 2017
Version: 0.0.2
Author: Miguel Mota
🌐
npm
npmjs.com › search
keywords:base64 to blob - npm search
npm tokens that bypass 2FA are being restricted — account changes (Aug 2026) and direct publishing (Jan 2027). Learn how to prepare →× ... Convert Base64 to Blob/File and Blob/File to Base64.
🌐
GitHub
github.com › jeremyBanks › b64-to-blob
GitHub - jeremyBanks/b64-to-blob
b64toBlob(b64Data: string, contentType?: string): Blob converts a base64 string to a Blob object as described in this Stack Overflow post. Note that the Blob class only exists in browsers, not Node, so this package is only meant for use in the ...
Starred by 46 users
Forked by 10 users
Languages: JavaScript 76.9% | TypeScript 23.1% | JavaScript 76.9% | TypeScript 23.1%
🌐
Libraries.io
libraries.io › npm › base64-blob
base64-blob 1.4.1 on npm - Libraries.io - security & maintenance data for open source software
October 11, 2018 - A module for interconversion of base64 and blob, wrapped by Promise - 1.4.1 - a JavaScript package on npm
🌐
GitHub
github.com › livelybone › base64-blob
GitHub - livelybone/base64-blob: A module for interconversion of base64 and blob · GitHub
npm i -S base64-blob · Base64_Blob ... developing another module, you should import it like this: import * as Base64_Blob from 'base64-blob' // then use it by need ·...
Author: livelybone
Find elsewhere
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

🌐
Libraries.io
libraries.io › npm › b64-to-blob
b64-to-blob 1.2.19 on npm - Libraries.io - security & maintenance data for open source software
August 20, 2017 - npm install b64-to-blob@1.2.19 · b64toBlob(b64Data: string, contentType?: string): Blob converts a base64 string to a Blob object as described in this Stack Overflow post. Note that the Blob class only exists in browsers, not Node, so this ...
🌐
npm
npmjs.com › package › blob-to-base64
blob-to-base64 - npm
February 26, 2019 - npm tokens that bypass 2FA are being restricted — account changes (Aug 2026) and direct publishing (Jan 2027). Learn how to prepare →× ... const blobToBase64 = require('blob-to-base64') const button = document.querySelector('.button') button.addEventListener('click', function (event) { const blob = document.querySelector('.input').files[0] blobToBase64(blob, function (error, base64) { if (!error) { document.querySelector('.result').innerHTML = base64 } }) })
      » npm install blob-to-base64
    
Published: Feb 26, 2019
Version: 1.0.2
🌐
Medium
jason150.medium.com › nodejs-base64-to-blob-a9803906fdc8
[NodeJS] Base64 to BLOB. Conclusion first: | by Jason Choi | Medium
November 30, 2020 - [NodeJS] Base64 to BLOB Conclusion first: var blob = Buffer.from(base64,”base64"); stack: client: React Native With Apllo Client server: NodeJS With Apollo Graphql Why I used this: Nowadays, the …
🌐
GitHub
github.com › miguelmota › base64toblob
GitHub - miguelmota/base64toblob: Base64 string to Blob object
May 24, 2022 - Convert a base64 string to a Blob object. https://lab.miguelmota.com/base64toblob · bower install base64toblob · npm install base64toblob ·
Author: miguelmota
🌐
npms
npms.io › search
blob to base64
npms was built to empower the javascript community by providing a better and open sourced search for node modules.
🌐
jsDelivr
jsdelivr.com › package › npm › b64-to-blob
b64-to-blob CDN by jsDelivr - A CDN for npm and GitHub
August 21, 2017 - `b64toBlob(b64Data: string, contentType?: string): Blob` converts a base64 string to a Blob object [as described in this Stack Overflow post](https://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript).
Published: Aug 20, 2017
🌐
npm
npmjs.com › package › blob-util
blob-util - npm
May 21, 2018 - Convert an ArrayBuffer to a Blob. ... Convert a base64-encoded string to a Blob.
      » npm install blob-util
    
Published: May 21, 2018
Version: 2.0.2
🌐
npm
npmjs.com › search
keywords:blob to base64 - npm search
npm tokens that bypass 2FA are being restricted — account changes (Aug 2026) and direct publishing (Jan 2027). Learn how to prepare →× ... Convert Base64 to Blob/File and Blob/File to Base64.
🌐
npm
npmjs.com › package › @maruware › blob-to-base64
@maruware/blob-to-base64 - npm
September 2, 2020 - Blob to base64. Latest version: 0.0.8, last published: 5 years ago. Start using @maruware/blob-to-base64 in your project by running `npm i @maruware/blob-to-base64`. There are 1 other projects in the npm registry using @maruware/blob-to-base64.
      » npm install @maruware/blob-to-base64
    
Published: Sep 02, 2020
Version: 0.0.8
Author: maruware
🌐
GitHub
gist.github.com › fupslot › 5015897
Javascript: Convert base64 to a Blob · GitHub
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 }); }
🌐
Npm
npm.io › search › keyword:base64+to+blob
Base64 to blob | npm.io
A module for interconversion of base64 and blob, wrapped by Promise · base64blobconversionbase64 to blobblob to base64dataUrl1.4.1 • Published 5 years ago