File Download At Front End Using Angular Js
Solution 1:
You will need to have your backend tell your front-end the location of the file, and then the front end can place a link to the file. The backend should probably generate a unique hash name for this file.
The actual file can be returned as part of a Rest GET request as long as the backend webserver has the correct mime types configured.
So in your controller you would call a service to get the file path:
SomeController.$inject = ['$http'];
var SomeController = function($http) {
varself = this;
$http.get('/download-file-path').then(function(path) {
self.path = path;
}
}
Then in your view
<divng-controller='SomeController as vm'><ang-href="{{vm.path}}">Download</a></div>
When angular calls GET: /download-file-path
the backend should return the name and path of the file, say something like /download/file-7dje79ae.xml
. Then angular puts this path in the a
link. When the user clicks the download button, the users browser will then make a request to /download/file-7dje79ae.xml
and download the file.
Post a Comment for "File Download At Front End Using Angular Js"