0

Hi guys I am trying to download a Base64 file but I get (we can't open this file) see the image and my code below

_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();
        }

    });
};
SpiderCode
  • 10,062
  • 2
  • 22
  • 42
  • What exactly does `we can't open this file` mean? You are creating a `text/plain` file which should be able to open with any text editor. – lin Feb 16 '18 at 12:28
  • Check this https://stackoverflow.com/questions/46405773/saving-base64-image-with-filesaver-js – Matej Marconak Feb 16 '18 at 12:33
  • Possible duplicate of [Saving base64 image with Filesaver.js](https://stackoverflow.com/questions/46405773/saving-base64-image-with-filesaver-js) – Matej Marconak Feb 16 '18 at 12:33

0 Answers0