【发布时间】:2016-04-21 18:53:44
【问题描述】:
我正在使用角度文件保护服务https://github.com/alferov/angular-file-saver 下载文件。下载很好,但是当尝试打开word文档时,我得到的文件已损坏,word无法打开它,如果将我的api直接放在浏览器文件中,当我打开它时很好,所以我想blob正在为这个问题做一些事情......对于.txt 文件我没有损坏它只适用于 .docx 和 .jpeg 或 .png。下面是我下载文件的短代码。
function downloadDocument(fileId, fileName, documentExt) {
var deferred = $q.defer();
var id = encodeURIComponent(fileId);
Restangular.one('download?fileId=' + id).get().then(function(data) {
var file = new Blob([data]);
if (documentExt && documentExt !== 'undefined') {
FileSaver.saveAs(file, fileName + '.' + documentExt);
}
else {
FileSaver.saveAs(file, fileName);
}
});
return deferred.promise;
}
【问题讨论】:
标签: javascript angularjs blob filesaver.js