0

I am trying to download image using angular js. Please check my download function

      $scope.downloadDocument = function (doc) {
        console.log(doc.fileName);
        $scope.array.nic = $stateParams.id;
        $http({
            method: "GET",
            url: appConfig.apiUrl + "/downloadDoc/" + $scope.array.nic + "/" + doc.fileName
        }).then(function (response) {
            console.log(response);
            $scope.downloadedImage = response.data;
            if (response.status == 200) {
                alertService.success("Document has been downloaded successfully.");
                $scope.alerts = alertService.get();
            }
            else {
                alertService.error(response.data.executionDescription);
                $scope.alerts = alertService.get();
            }
        }, function (response) {
            $log.log(response);
        });

    }

above GET request is success with 200 state. but file is did not download. I console log the response also. please check the below response.

enter image description here

this is my current download button

<button class="btn btn-success btn-flat btn-xs" type="button"
                                                ng-disabled="document.submitted === false"
                                                ng-click="downloadDocument(document)">
                                                <i class="fa fa-download"> </i>
                                            </button>

How i create download button using above response. can you help me for do it ? thanks

Kumara
  • 471
  • 2
  • 10
  • 33

1 Answers1

-1

The link below show how to download image in base64, hope that It will help.

https://stackoverflow.com/questions/14011021/how-to-download-a-base64-encoded-image
Thomson Mixab
  • 657
  • 4
  • 8