CordovaFile & CordovaFileTransfer. How get correct name of file, with correct type file


#1

I have a project that loads the files from site. In the browser, click a link (http://www.uzhnu.edu.ua/uk/infocentre/get/6500), it loads files at once with сorrectly name and extension. How to implement it in the ionic app, I do not know.
File downloaded from url, where $scope.id is id of file (etc. 6500)
Help me please, or give some ideas how solve this.

$scope.downloadFile = function() { $ionicLoading.show({template: 'Download file...'}); var url = "http://www.uzhnu.edu.ua/uk/infocentre/get/"+$scope.id; var filename = $scope.id+".doc"; alert(filename); var targetPath = "/storage/sdcard0/documents/" + filename; var trustHosts = true var options = {}; $cordovaFileTransfer.download(url, targetPath, options, trustHosts) .then(function() { // Success! $ionicLoading.hide(); alert('File download ' + targetPath); }, function(error) { $ionicLoading.hide(); // An error occured. Show a message to the user alert('Sorry'); alert(JSON.stringify(error)); }); };