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


I have a project that loads the files from site. In the browser, click a link (, 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 $ is id of file (etc. 6500)
Help me please, or give some ideas how solve this.

$scope.downloadFile = function() { ${template: 'Download file...'}); var url = ""+$; var filename = $".doc"; alert(filename); var targetPath = "/storage/sdcard0/documents/" + filename; var trustHosts = true var options = {}; $, 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)); }); };