【发布时间】:2015-10-27 05:19:40
【问题描述】:
我正在尝试使用 angular-file-saver 下载 base64 文件。
我可以在没有 angular-file-saver 的情况下使用这个 html 标记来做到这一点:
<a ng-href="data:{{document.mimeType}};base64,{{document.base64Code}}" target="_blank" download>Download Single Document</a>
我现在有其他需求可以通过 angular-file-saver 满足,这导致我过渡到使用 FileSaver 执行此操作。现在我想使用文件保护程序实现相同的下载。我的 html 标记是:
<a ng-href="#" ng-click="downloadFile()">Download with File Saver</a>
然后我像这样构建我的 downloadFile 函数:
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);
}
我的问题是,当我尝试打开文件下载文件后,文件已损坏。
我假设我通过连接“;base64”对类型对象做错了什么。我已经开始深入研究 angular-file-saver.bundle.js,但非常感谢任何帮助。我做错了什么?
【问题讨论】: