Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript dataurl to blob

function dataURItoBlob(dataURI) {
  // convert base64 to raw binary data held in a string
  // doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
  var byteString = atob(dataURI.split(',')[1]);

  // separate out the mime component
  var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]

  // write the bytes of the string to an ArrayBuffer
  var ab = new ArrayBuffer(byteString.length);

  // create a view into the buffer
  var ia = new Uint8Array(ab);

  // set the bytes of the buffer to the correct values
  for (var i = 0; i < byteString.length; i++) {
      ia[i] = byteString.charCodeAt(i);
  }

  // write the ArrayBuffer to a blob, and you're done
  var blob = new Blob([ab], {type: mimeString});
  return blob;

}
Comment

PREVIOUS NEXT
Code Example
Javascript :: react toggle boolean state 
Javascript :: remove element from an array 
Javascript :: jquery change text color 
Javascript :: mongoose populate filter 
Javascript :: generate random string javascript 
Javascript :: js window width change 
Javascript :: import bootstrap css and js file in react 
Javascript :: js keydown only once 
Javascript :: add jquery cdn 
Javascript :: how to cut a string in js 
Javascript :: committing parts of a file git 
Javascript :: angular minutes to hour and minutes 
Javascript :: eliminar el ultimo caracter de un string javascript 
Javascript :: js domtokenlist to array 
Javascript :: responsive grid using antd 
Javascript :: string to in js 
Javascript :: Error serializing `.list Data` returned from `getStaticProps` 
Javascript :: moment month start date and end date 
Javascript :: mongoose generate objectid 
Javascript :: react image compression 
Javascript :: bootstrap modal disable close on click outside react bootstrap 
Javascript :: inline style jsx 
Javascript :: install react js 
Javascript :: javascript length 
Javascript :: get all from dir node 
Javascript :: javascript reduce array of objects 
Javascript :: electron no menu bar 
Javascript :: javascript string unique characters 
Javascript :: how to remove special characters from a string in javascript using regex 
Javascript :: how to generate random string in javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =