下载AngularJS中的Base64

时间:2018-02-16 12:26:06

标签: angularjs

大家好我想下载一个Base64文件,但我得到(我们无法打开此文件),请看下面的图片和我的代码

_thisSearchView.$scope.downloadViewAttachment = function (firstId) {

    var idValue = couchObjectId.substr(4, couchObjectId.indexOf('_rev=') - 4);


    $http.defaults.headers.common['Authorization'] = "Basic " + _thisSearchView.$scope.config.params.COUCHDB_SERVER_KEY;

    $http({
        method: "GET",
        url: _thisSearchView.$scope.config.params.COUCHDB_SERVER_URL + idValue + '/' + attachName,
    }).then(function mySuccess(response) {



         try {
             var blob = new Blob([response.data], {
                 type: "text/plain;charset=utf-8"
             });
             saveAs(blob, attachName);
           }
         catch (ex) {   
             console.log(ex);
         }

    }, function myError(response) {
        if (response.status === 404) {
            _thisSearchView.$scope.downloadViewArchDcoument();
        }

    });
};

0 个答案:

没有答案