I read all the Cordova file related documents but didn’t find a proper way to download the files from an app into device internal memory. Can anyone help with this, please ?
$scope.download = function download(name, contentType, fileLInk) {
ionic.Platform.ready(function() {
var url = apiServiceBaseUri + fileLInk;
var targetPath = cordova.file.dataDirectory + 'myapp/' + name;
var trustHosts = false;
var options = {
headers: {
'Authorization': tokenType + ' ' + accessToken
}
};
$cordovaFileTransfer.download(url, targetPath, options, trustHosts)
.then(function(result) {
var alertPopup = $ionicPopup.alert({
title: 'File has been downloaded',
});
$ionicListDelegate.closeOptionButtons();
}, function(error) {
$ionicListDelegate.closeOptionButtons();
if (error.http_status == 401) {
$ionicPopup.alert({
title: 'Oops, Session is expired!',
template: 'Looks like your session is expired or you logged in from someother device.'
});
$ionicHistory.clearCache().then(function() {
$state.go('start.login');
});
}
var alertPopup = $ionicPopup.alert({
title: 'Sorry, something went wrong during the request!',
template: error.data.errors[0].message
});
});
});
};