how to download a zip file

后端 未结 3 1187
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 04:00

I am trying to download a zip file from my web api controller. It is returning the file but I am getting a message the zipfile is invalid when i try to open. I have seen oth

3条回答
  •  悲&欢浪女
    2020-12-09 04:35

    Below code is working fine for me for download zip file,

    Controller

    $scope.downloadExport = function (id,filename,frmdata) {
             frmdata = {};
            var data = tdioServices.downloadexport(id,filename,frmdata);
             data.success(function(success) {
                    var blob = new Blob([success], { type:"arraybuffer" });           
                    var downloadLink = angular.element('');
                    downloadLink.attr('href',window.URL.createObjectURL(blob));
                    downloadLink.attr('download', filename);
                    downloadLink[0].click();
                    $COMMON_ACCEPT = "Download Successfully";
                    $COMMON_ACCEPT_TEXT = "Success";
                    toastr.success($COMMON_ACCEPT, $COMMON_ACCEPT_TEXT);
    
            });
        };
    

    Services

     this.downloadexport = function(id,filename,frmdata){
           var request = $http({method:'get', url:APP_URL+'/exports/'+id+'/download/'+filename, data:frmdata,responseType:'arraybuffer'});
           return request;        
        }
    

提交回复
热议问题