title: How to download an image File and save into local hard drive using AngularJS by calling Web Services
body: <p>My Requirement is</p>
  
  <ol>
  <li><p>In web application if I click a download link, a REST web service call is be made.</p></li>
  <li><p>Response of the Web Service  is byte[] and Content-Disposition=[attachment;]</p></li>
  <li><p>Saving the response into local drive by popping up a dialogue box.</p></li>
  </ol>
  
  <p>I have tried with ajax call and successfully getting byte[] response, but can't save into local hard drive. The code snippet is below.</p>
  
  <p>HTML code is</p>
  
  <pre><code>&lt;div data-ng-app="myApp"  data-ng-controller="myCtrl" &gt;
    &lt;a href="#" data-ng-click="downloadImage()"&gt;download&lt;/a&gt;
  &lt;/di&gt;
  </code></pre>
  
  <p>Angular Script is </p>
  
  <pre><code>   angular.module("myApp", []).controller("myCtrl", function ($scope, $http){
  
       $scope.downloadImage= function (){     
             var responsePromise = $http.get(resourceUrl);
  
             responsePromise.success(function (data) {
                alert("File Stream:"+data);
             });
  
             responsePromise.error(function(data) {
               alert("AJAX failed! in downloading Image:"+ data);
             });
        }
      });
  </code></pre>
  
  <p>In alert, I am getting full stream as byte[]. I want to save into local hard disk. I understand that response is stored in browser memory, but how to redirect storing into local drive?</p>
  
  <p>Any suggestions would be appreciated.</p>
  
  <p>Should not we use ajax call for this? If not, what is the alternative approach?</p>
  
  <p>Can anyone help me how to resolve this as it is my high priority.</p>