-1

I have a route on my server that is used to serve files for download. Because of the nature of the app I cannot have a link to any file. Instead the browser client requests the file to the server which in turn request the file from a node client which returns the data back to the server. At this point the server saves the file and notifies the caller browser of the file being ready for request. Im using angular in the front end and to request the file I was trying to use $http.get(), with that in chrome's dev tools I could see the request happening successfully but the file would not download. Typing the link address outside of angular would download the file. In turn I ended up using$window.location.assign(url) and that did work. Could anyone explain why assign() worked and not $http.get()? What are the differences?

Thanks

LouieV
  • 1,032
  • 2
  • 15
  • 28

1 Answers1

0

You can't download a file using an AJAX request or better say XHR... Angular make use of this when making calls.

Refer to this : Why threre is no way to download file using ajax request?

So easiest is to stick with what you are doing right now or make use of some third party utility.

Community
  • 1
  • 1
Ash
  • 2,575
  • 2
  • 19
  • 27