5

I'm trying to Convert data URI to image data but I faced this error:

Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded

the function:

function dataURLtoBlob(dataurl) {
  var arr = dataurl.split(',');
  var mime = arr[0].match(/:(.*?);/)[1];
  var bstr = window.atob(arr[1]);
  var n = bstr.length;
  var u8arr = new Uint8Array(n);

  while (n--) {
    u8arr[n] = bstr.charCodeAt(n);
  }
  return new Blob([u8arr], {
    type: mime
  });
}

dataurl is:

src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAgAElEQVR4Xmy9edRl6VXe95z5nHvuvd9Uc5W6q9WSWiOSGISEmCQmx2ZKCAtjsryygv9JVsY/SGwSRw54GezYBiHANEkV7WeKQBWriul64VufPLj2vMCbSUTqQU5OAPx2lIl+S0qZWAskN2jLhaZ5ioaZRZBgMbG1AL…

user7637745
  • 965
  • 2
  • 14
  • 27
amal mansour
  • 345
  • 2
  • 5
  • 14

0 Answers0