如何使用AngularJS下载二进制文件
下载二进制文件时,重要的是设置
responseType:
app.service('VerDocServices',['$http',function($http) { this.downloadFile = function(url, file, urlDir) { var config = { //SET responseType responseType: 'blob', params : { file : file, urlDir : urlDir } }; return $http.get(url, config) .then(function(response) { return response.data; }).catch(function(response) { console.log("ERROR: ", response.status); throw response; }); }; }]);如果
responseType省略,则XHR
API默认将UTF-8编码的文本转换为DOMString(UTF-16),这将损坏PDF,图像和其他二进制文件。
有关更多信息,请参见MDN Web API参考-XHR ResponseType



