blob to json (angular download excel table blob data stream interface returns error)

Today, I encountered an example of downloading a data table, and the interface returned an error. The BLOB object needs to be converted into a JSON object:

FileReader object is used

 this.ctrl.downloadHistoryAlarms(this.PARMAR).subscribe(
            res => {
                // success execute code
            },
            failed => {
                let reader = new FileReader();
                reader.onload = e =>{
                   // The interface provided by the common prompt box used in the project failedMsg
                   // The converted json is in the e.target ["result"] attribute
                    this.commS.failedMsg('alarm.excel.download', 
                   {"error":JSON.parse(e.target["result"])})
                };
                // The value of failed.error is a blob object
                reader.readAsText(failed.error);
            }
        );

  

Guess you like

Origin www.cnblogs.com/dangou/p/12699012.html