错误:DOMException:无法在“ Window”上执行“ atob”:要解码的字符串未正确编码

时间:2019-01-14 10:48:03

标签: typescript angular6

DOMException:无法在“ Window”上执行“ atob”:要解码的字符串未正确编码。

我正在尝试单击一次下载pdf文件。但这显示了一个错误 在这里,我创建了fixBinary函数,并使用filesaver.js下载了pdf

html代码:

<th>Download</th>
<th>
<a style="color: green;font-size: x-large;cursor: pointer;" (click)="GetDocumentId()"><i class='mdi mdi-download'></i></a>
</th>

打字稿代码:

GetDocumentId() {
  debugger;
this._auth.GetDocument(this.accessionNo,this.userID,this.token).subscribe(
  (data: any) => {
    setTimeout(() => {
      debugger;
      if (data.length > 0) {
        debugger;
      var dataid= data[0];;
        console.log(dataid);
         this.download(dataid);
      }
    }, 1000);
  },
  error => {}
);
}
}


public download(Document:any) {
// this.loaderVar = true;

 this._auth
   .GetUploadedWithBinaryDataFiles(Document.SDocumentID,this.userID,this.token)
   .subscribe(data1 => {
     setTimeout(() => {

       this.base64string = Document.docBase64;
       if (this.base64string.length > 1000) {
         this.base64string = this.base64string.substring(
           this.base64string.lastIndexOf(",") + 1,
           this.base64string.length - 1
         );

         this.Data64ArrayBuffer = this._auth.fixBinary(
           atob(this.base64string)
         );

         var blob = new Blob([this.Data64ArrayBuffer], {
           type: Document.DocType
         });

         fileSaver.saveAs(blob, "Report"+Document.SDocumentID+".pdf");
    //     this.loaderVar = false;
       }
     }, 1000);
   }, this.Errorfunction);
}

0 个答案:

没有答案