downloading xlsx file in angular 2 with blob

前端 未结 6 720
悲&欢浪女
悲&欢浪女 2021-01-02 02:31

I want to download xlsx file from the client on angular 2 using rest api.

I\'m getting a byte array as a response from my GET request and I\'m sending it to download

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 03:25

    Here is the solution that supports IE and chrome/safari browsers. Here 'response' object is response received from service. I have this working for archive. You can change the type as per the response received from service.

        let blob = new Blob([response], {type: 'application/zip'});
        let fileUrl = window.URL.createObjectURL(blob);
        if (window.navigator.msSaveOrOpenBlob) {
            window.navigator.msSaveOrOpenBlob(blob, fileUrl.split(':')[1] + '.zip');
        } else {
            this.reportDownloadName = fileUrl;
            window.open(fileUrl);
        }
    

提交回复
热议问题