Ioninc how to convert Base64 To Blob


#1

following is my code and it is not working window.atob(b64Data) has issue
// my API return a base64 string

saveAndOpenPdf1()
{
this.url1 = “http;//www.gogole.com”;

  this.ReportData.GetPDFData(this.url1)
    .subscribe((data) => {

      let filenamevalue="pdf";

      const writeDirectory = this.platform.is('ios') ? this.file.dataDirectory : this.file.externalDataDirectory;

      this.file.writeFile(writeDirectory, filenamevalue, this.convertBase64ToBlob(data, 'data:application/pdf;base64'), { replace: true })
        .then(() => {

          this.fileOpener.open(writeDirectory + filenamevalue, 'application/pdf')
            .catch(() => {
              console.log('Error opening pdf file');
          
            });
        })
        .catch(() => {
          console.error('Error writing pdf file');
          
        });

    },
      (error) => {
        console.log('in subscribe error');
        console.log(error);
      });

}

convertBase64ToBlob(b64Data : string, contentType : string): Blob 
{
  contentType = contentType || '';
  const sliceSize = 512;
  b64Data = b64Data.toString().replace(/^[^,]+,/, '');
  b64Data = b64Data.toString().replace(/\s/g, '');
  const byteCharacters = window.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);
  }

  return new Blob(byteArrays, { type: contentType });
}




Please provide me a solution.
There is already alots issue in Ionic framework.
I need solution to convert base64 to file which is downloaded in Android 5.0 application .

Thanks