title: Angular how to download file from S3 Amazon using ng-click
body: <p>I am trying to download a file from my amazon S3 bucket by using angular ng-click. But instead of file it returns me with blank file on download.</p>
  
  <h1>HTML</h1>
  
  <pre><code>&lt;div class="details-field"&gt; RC Book 
    &lt;font class="digit" &gt;({{rcCount}})&lt;/font&gt; : &lt;i class="fa fa-angle-down fa-button" ng-click=download() &gt;&lt;/i&gt;
  &lt;/div&gt;
  </code></pre>
  
  <h1>Angular script</h1>
  
  <pre><code>var awsUrl = https://s3.amazonaws.com/thdoc/ ;
  $scope.download = function() {
    $http.get(awsUrl, {
      responseType: "arraybuffer"
    })
    .success(function(data) {
       var anchor = angular.element('&lt;a/&gt;');
       var blob = new Blob([data]);
       anchor.attr({
         href: window.URL.createObjectURL(blob),
         target: '_blank',
         download: 'RCBook_406_20170328_222831_644.jpg'
       })[0].click();
    })
  }
  </code></pre>
  
  <p>Any help will be great on this issue.</p>
  
  <p>Thanks</p>