ngCordova $cordovaFile returns Encoding Error (5)


#1

I am using ngCordova and specifically the module $cordovaFile to remove a file from a specific location. More specific, I want to remove an image, which I saved before using this tutorial.

This works fine as my image is saved in the folder (iOS):

file:///var/mobile/Containers/Data/Application/[APP_ID]/Library/NoCloud/

Note that using cordova.file.dataDirectory I can also get this location.

Now I have an image of which I have the nativeURL in the format as shown above:

file:///var/mobile/Containers/Data/Application/[APP_ID]/Library/NoCloud/imagename.jpg

(the url is valid as it displays the image in the DOM when I use the <img ng-src="nativeURL"> tag).

I am trying to delete this image using the following syntax - but that throws me an encoding error 5:

var removeFile = function(nativeURL) {
        
        var name = nativeURL.substr(nativeURL.lastIndexOf('/') + 1);        
        
        $cordovaFile.checkFile(cordova.file.dataDirectory, name)
        .then(function (success) {
            
            window.alert("file found " + success)
            
            $cordovaFile.removeFile(cordova.file.dataDirectory, name)
            .then(function (success) {
                // success
                window.alert("file deleted " + success)
            }, function (error) {
                // error
                window.alert("file not deleted error " + error)
            });
            
        }, function (error) {
        // error - here I get the ENCODING_ERR 5
            window.alert("file not found " + JSON.stringify(error))

        });
        
    }

#2

Anyone an idea how to resolve this?


#3

Same here and no clue. I think it is a problem with the current version of ngCordova as i got the same process working in an older app…

Would love some help…


#4

This is what i used to perfom my task :

      window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fs) {
          fs.root.getFile(fileNativeURI.substring(fileNativeURI.lastIndexOf('/') + 1), {create: false}, function(fileEntry) {

            fileEntry.remove(function() {
              console.log('File removed.');
            }, errorHandler);

          }, errorHandler);
        }, errorHandler);

Hope it helps.