Reputation: 174
i'm new in cordova and ionic
i want to download audio file from server
my ionic version is : 1.7.14
my cordova version is : 6.1.1
my android version is : 6 ( I use encrypt mode )
here is my code :
$scope.DownloadFile = function (url, filename) {
var ft = new FileTransfer();
var source = encodeURI('http://' + url + filename);
var targetPath = cordova.file.documentsDirectory + filename;//change path as you need
var trustHosts = true;//optional
var options = {};//optional
ionic.Platform.ready(function () {//device prepared
ft.download(source, targetPath, function (entry) {
alert('success' + JSON.stringify(entry));
}, function (err) {
alert(url + filename);
alert(JSON.stringify(err));
}, trustHosts, options);
});
}
I get this result :
{"code":1 , "source":"http://sedaban.com/sedaban/users/json/app/mobile/download/146012022293952.mp3","target":"null146012022293952.mp3","http_status":200,"body":null,"exception":"/null146012022293952.mp3:open failed: EROFS (Read-only file system)"}
Upvotes: 1
Views: 1710
Reputation: 11935
cordova.file.documentsDirectory is not valid for Android.
This is the description mentioned in cordova file plugin github - "cordova.file.documentsDirectory - Files private to the app, but that are meaningful to other application (e.g. Office files). Note that for OSX this is the user's ~/Documents directory. (iOS, OSX)"
Try out cordova.file.externalDataDirectory or cordova.file.externalRootDirectory for Android. Hope it helps
Upvotes: 1