Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度文件保护程序使用FileSaver下载base64文件_Angularjs_Filesaver.js - Fatal编程技术网

Angularjs 角度文件保护程序使用FileSaver下载base64文件

Angularjs 角度文件保护程序使用FileSaver下载base64文件,angularjs,filesaver.js,Angularjs,Filesaver.js,我正在尝试使用angular文件保护程序下载base64文件 我可以在没有角度文件保护程序的情况下通过以下html标记完成此操作: <a ng-href="data:{{document.mimeType}};base64,{{document.base64Code}}" target="_blank" download>Download Single Document</a> 我的问题是,文件下载后,当我试图打开它时,该文件已损坏 我假设通过连接“base64”,我对

我正在尝试使用angular文件保护程序下载base64文件

我可以在没有角度文件保护程序的情况下通过以下html标记完成此操作:

<a ng-href="data:{{document.mimeType}};base64,{{document.base64Code}}" target="_blank" download>Download Single Document</a>
我的问题是,文件下载后,当我试图打开它时,该文件已损坏


我假设通过连接“base64”,我对类型对象做了一些错误的处理。我已经开始深入研究angular-file-saver.bundle.js,但非常感谢您的帮助。我做错了什么?

最后我挖了个坑,遇到了这个堆栈溢出来让它工作。

为了补充答案,我建议将npm validator添加到您的解决方案中。在尝试下载或转换为blob之前,可以验证您的sting是base64。
<a ng-href="#" ng-click="downloadFile()">Download with File Saver</a>
function downloadFile () {
        var data = new blob([$scope.document.base64Code], {type: $scope.document.mimeType+';base64'});
        var config = {
            data: data,
            filename: $scope.documentSaveAs ? $scope.documentSaveAs : $scope.document.FileName
        }
        fileSaver.saveAs(config);
    }