I have developed a service to retrieve and save files from a specified URL.
(function() {
angular.module('SOME_APP')
.service("downloadService", downloadService);
function downloadService($http){
var downloadFileFromUrl = downloadFileFromUrl;
function downloadFileFromUrl(url){
if(!url.length){
//TODO handle the error
}
else{
//extract the file name and extension for saving purposes:
var fileName;
for(var i=url.length; i>=0; i--){
if(url[i]=='/'){
fileName=url.slice(i+1, url.length);
console.log(fileName);
break;
}
}
$http({
url: url,
method: "GET",
responseType: 'arraybuffer'
}).success(function (data) {
var blob = new Blob([data], {type: '*/*'});
saveAs(blob, fileName);
}).error(function (data) {
console.log(data);
//TODO error handling
});
}
}
return {
downloadFileFromUrl : downloadFileFromUrl
}
}
}());
After calling the service, it currently downloads the file first and then displays it in the browser with progress reaching 100%. How can I modify it to work normally by initiating the download in the browser and showing the progress gradually?