Search code examples
angularjscordovaionic-frameworkcordova-plugins

What is the Cordova file function success object type?


I am trying to figure out the type of the success object for any of the cordova file API functions? For instance, for the checkFile function it should logically be a boolean true / false reply. Or is the then branch the positive - file exists branch and the error branch when the file does not exist?

$cordovaFile.checkFile(cordova.file.dataDirectory, "some_file.txt")
      .then(function (success) {
        // success
      }, function (error) {
        // error
      });

However, it's pretty hard to tell from the documentation. Docs states: Returns Object , and since it seems difficult to detect from a standard browser, it's some dark magic phone debugging to get familiar with the API. Any hints welcome.


After some exercises and looking at the source code, this is how I now got to understand the cordova file library with the checkFile function:

this.checkBackupExists = function(){
        var deferred = $q.defer();

        $cordovaFile.checkFile(cordova.file.dataDirectory, this.backupFileName)
        .then(function (success) {
            deferred.resolve(true);
        }, function (error) {
            // error
            if(error.code==1) #NOT_FOUND_ERR
                deferred.resolve(false);
            else
                deferred.reject(error);
        });
        return deferred.promise;
    }

Solution

  • I believe that a successful run of 'checkFile' with result in the 'then' callback being called and and of the errors occurring here http://ngcordova.com/docs/plugins/file/#file-error-codes will result in the 'error' callback being called... with 'error' being that error code or an object containing the code.