1

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

2
  • why cant you directly bind the url to href Commented Feb 5, 2018 at 6:18
  • @Sajeetharan can you please replica that one. Thanks Commented Feb 5, 2018 at 6:19

1 Answer 1

2

You need something like this,

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

DEMO

Sign up to request clarification or add additional context in comments.

9 Comments

But i have different buttons for different files how could i check to download that file using this ?
you need to use ng-repeat
how ? sorry but i am getting confused.
you need to create a list of objects with name and url, then use ng-repeat to generate buttons with href set from the object
yaa used your code with some simple logic. Thanks for youe help.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.