Ionic-native/file unexpected behavior, 1: NOT_FOUND_ERR

So I’m working on an app. One of the steps the app takes is that when you take a picture it saves it localy, in this case, to file:///data/user/0/appname/cache/

Saving the file is no problem. The issue comes when its time to allow an user to access that file. I’ve written a method that is supposed to check for the file’s presence before doing anything else. To do this we import the File provider. As so:


import { File } from '@ionic-native/file';

Then we dependency inject it in the constructor

constructor(public file: File,
              public platform: Platform) {
        this.platform.ready().then(() => {
           this.storageDirectory = cordova.file.cacheDirectory;
     }
  }

So far so good! this.storageDirectory gets set just fine. The issue comes when its time to see if the file exists. i’ve narrowed down the issue code to the following. I’ve replaced the internal methods with console.logs for simplicity in reproducing the error

genFlie(fileName){
  return this.file.checkFile(this.storageDirectory, fileName).then(
         (res)=>{console.log(res)},
         (err)=>{console.log(err)}
  )
}

instead of res being true or false depending on if the file exists, which is the expected behavior, what happens is an error is raised, specifically, 1: NOT_FOUND_ERR. Which seems to entirely defeat the point of having a checkFile function. I found this fix on github but it didn’t actually solve anything for me. I have been trying to solve this issue for two days now, and am at my wits end, any help is appreciated.

Other details, I’m using Android Studio to emulate android, specifically on the nexus 6, API 26.

One solution/workaround would be to return false from the error handler, e.g.

return this.file.checkFile(this.storageDirectory, fileName).then(
    (res) => res,
    (err) => false
).then(fileExists => {
    console.log('does my file exist?', fileExists);
});

If this is indeed an issue, it may be good to post this as an issue on the Ionic Native github page.

This is what I will do, thanks for the suggestion.

I have opened an issue on the Ionic Native github as per your suggestion.

If anyone has insight into this behavior though, I’d still appreciate it, the plugin isn’t entirely transparent on how it handles things.