简体   繁体   中英

Angular how to download file from S3 Amazon using ng-click

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.

HTML

<div class="details-field"> RC Book 
  <font class="digit" >({{rcCount}})</font> : <i class="fa fa-angle-down fa-button" ng-click=download() ></i>
</div>

Angular script

var awsUrl = https://s3.amazonaws.com/thdoc/ ;
$scope.download = function() {
  $http.get(awsUrl, {
    responseType: "arraybuffer"
  })
  .success(function(data) {
     var anchor = angular.element('<a/>');
     var blob = new Blob([data]);
     anchor.attr({
       href: window.URL.createObjectURL(blob),
       target: '_blank',
       download: 'RCBook_406_20170328_222831_644.jpg'
     })[0].click();
  })
}

Any help will be great on this issue.

Thanks

You need something like this,

<a href="{{ url }}" target="_blank" >Trusted URL</a><br><br>

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM