1
votes

I have been trying to copy/move files from the tmp directory to either the Documents or the Library directory in my app on iOS.

Both fail miserably giving me an error. (error code 6 NO_MODIFICATION_ALLOWED_ERR).

https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md

According to the documentation here I should theoretically be able to transform the paths into a directory object and then be able to move/copy files there. Documents and Library have r/w access. The documentation doesn't say anything about requesting a FileSystem first and all that. So I am a bit puzzled about what to do to actually be able to copy files into persistent storage.

window.resolveLocalFileSystemURL(fileURL, function(file){
    console.log('Moving File');
    file.moveTo(window.MainApp.FolderObject, newName, window.MainApp.SuccessHandler, window.MainApp.ErrorHandler);
}, window.MainApp.ErrorHandler);

The FolderObject is created like this:

window.resolveLocalFileSystemURL(window.MainApp.FileFolder,function(dir){
        window.MainApp.FolderObject = dir;
    }, window.MainApp.ErrorHandler);

And the MainApp.FileFolder points to: file:////Library/

Also the directories referred to in the documentation do not resolve when testing it through the console. That's the reason why copying files to the supposedly accessible Documents folder fails.

Please help, this is extremely frustrating and confusing.

1
Hi, I know that the question was asked two years ago but i am facing the same problem as you did.and after so much googling i didn't find an answer.Can you tell me how did you solve this problem thanx in advance. - Hadj Ali Oussama
I posted an answer to my own question with some hints for you. If you run into more problems I can dig deeper. - Flobbo

1 Answers

0
votes

I don't exactly recall how I ended up solving the problem because it's been a while but I went into my code and found this function which resides in the onDeviceReady part:

window.resolveLocalFileSystemURL(cordova.file.dataDirectory,function(dir){
        window.MainApp.FolderObject = dir;
    }, window.MainApp.ErrorHandler);

This seems to open up the permanent storage for usage inside the app because the window.MainApp.FolderObject is referenced throughout and does its job. Hope this helps.