src/methods.js
function base64ToBlob(base64Image, contentType) {
  // http://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript

  // Remove leading 'data:image/jpeg;base64,' or 'data:image/png;base64,'
  base64Image = base64Image.split(',')[1];

  let byteCharacters = atob(base64Image);

  // http://stackoverflow.com/questions/6259515/javascript-elegant-way-to-split-string-into-segments-n-characters-long
  let byteArrays = byteCharacters.match(/[\s\S]{1,512}/g).map( slice => {

    let byteNumbers = slice.split('').map( x => x.charCodeAt(0) );

    return new Uint8Array(byteNumbers);
  });

  let blob = new Blob(byteArrays, { type: contentType || 'image/jpg' /* or 'image/png' */ });

  return blob;
}
function base64ToBlob(base64Image, contentType) {
  // http://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript

  // Remove leading 'data:image/jpeg;base64,' or 'data:image/png;base64,'
  base64Image = base64Image.split(',')[1];

  let byteCharacters = atob(base64Image);

  // http://stackoverflow.com/questions/6259515/javascript-elegant-way-to-split-string-into-segments-n-characters-long
  let byteArrays = byteCharacters.match(/[\s\S]{1,512}/g).map( slice => {

    let byteNumbers = slice.split('').map( x => x.charCodeAt(0) );

    return new Uint8Array(byteNumbers);
  });

  let blob = new Blob(byteArrays, { type: contentType || 'image/jpg' /* or 'image/png' */ });

  return blob;
}
function base64ToBlob ( base64Image , contentType ) { // http://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript // Remove leading 'data:image/jpeg;base64,' or 'data:image/png;base64,' base64Image = base64Image . split ( ',' ) [ 1 ] ; let byteCharacters = atob ( base64Image ) ; // http://stackoverflow.com/questions/6259515/javascript-elegant-way-to-split-string-into-segments-n-characters-long let byteArrays = byteCharacters . match ( / [\s\S]{1,512} / g ) . map ( slice => { let byteNumbers = slice . split ( '' ) . map ( x => x . charCodeAt ( 0 ) ) ; return new Uint8Array ( byteNumbers ) ; } ) ; let blob = new Blob ( byteArrays , { type : contentType || 'image/jpg' /* or 'image/png' */ } ) ; return blob ; }
Converts Base64 image into a blob file.
@param {string} base64Image Base64 image string.
@param {string} contentType 'image/jpg' or 'image/png'.
@returns {file} Image file as a blob.
Converts Base64 image into a blob file .