ngCordova save file to device (iOS)

I’m trying to save a remote file to the file system on iOS. It works flawless on Android, but on iOS I get the following error:

2014-10-07 12:09:00.091 xxx-appen[1072:486447] FileTransferError {
body = “Could not create path to save downloaded file: The operation couldn\U2019t be completed. (Cocoa error 513.)”;
code = 1;
“http_status” = 200;
source = “https://remoteurltoimage”;
target = “cdvfile://localhost/root/var/mobile/Applications/uuid/app-name/Documents/NoCloud/251182.jpg”;
}

I’ve tried a multitude of different paths to store the file, without app-name and different directories according to the info here:
http://plugins.cordova.io/#/package/org.apache.cordova.file

My plugins are:
com.ionic.keyboard 1.0.3 “Keyboard”
org.apache.cordova.console 0.2.11 “Console”
org.apache.cordova.device 0.2.12 “Device”
org.apache.cordova.file 1.3.1 “File”
org.apache.cordova.file-transfer 0.4.6 “File Transfer”
org.apache.cordova.geolocation 0.3.10 “Geolocation”
org.apache.cordova.inappbrowser 0.5.2 “InAppBrowser”
org.apache.cordova.splashscreen 0.3.3 “Splashscreen”
org.apache.cordova.statusbar 0.1.8 “StatusBar”

What am I missing?

1 Like

I think you do not have the rights to create a file/folder under “var”.

More information can be found here:
https://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/index.html

1 Like

I found a script that makes this a lot more beautiful than setting it to a fixed value. The below finds the correct path to a persistent storage directory. I store that path in a global value used by different file service methods.

//Find persistent storage path
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
persistentFilePath = fileSystem.root.toURL();
}, function(){
alert(“No access to read persistent storage path”);
});

Works in both iOS and Android.

You can read here: Xoilac TV - Website Trực Tiếp Bóng Đá Số 1 VN XoilacTV

target: you should get path (where save files) by cordova.file.*
Hope you can do it