-1

I have a rest service for file download, I test and it works if I just copy paste the url to addres bar in browser I can see the browser pop up window ask me to save the file:

myaddress/assets/csvreport

BUT using AngularJs with a download button, there is no pop up window if I use it like this;

       $scope.downloadAssets = function () {
         $http({
               method: 'GET',
               url: '/assets/csvreport',
               params: criteria
        })

I call this method from my html like this;

 <input ng-click="downloadAssets()" value="Download" type="submit">

This only returns the string in response and I can not see any browser file save pop-up

Any Ideas? It needs to work on IE8

Spring
  • 11,333
  • 29
  • 116
  • 185

1 Answers1

1

The $http is not for downloading file. It's for calling AJAX things. You can just redirect the page to that url:

$scope.downloadAssets = function () {
  var querystring = buildQueryString( criteria )
  window.location = '/assets/csvreport?' + querystring;
}

You can find the buildQueryString function here : How to build query string with Javascript;

Community
  • 1
  • 1
Hereblur
  • 2,084
  • 1
  • 19
  • 22
  • tnx and how can I add my paremeters, I think this will also change how I handle the params in the backend as well? – Spring Feb 20 '14 at 10:05
  • I added some code to show you how to add parameter, And you dont have to change on the server side, It's work the same way as before. – Hereblur Feb 20 '14 at 10:41
  • can I add my authentication token to header? – Spring Feb 20 '14 at 12:06