file.checkFile FileError {code: 1, message: "NOT_FOUND_ERR"}

Hi,

I’m new to Ionic and I have trouble when I try to check if a file exists on android. I don’t know what’s wrong. I can see the file in the directory when I use listDir (this.file.listDir(this.file.applicationDirectory, ‘www/’)). But when I try: this.file.checkFile(this.file.applicationDirectory + ‘www/’, ‘database.db’) I got the error {code: 1, message: “NOT_FOUND_ERR”}.

My code:

this.file.listDir(this.file.applicationDirectory, ‘www/’)
.then(items =>{
for(let i in items){
console.log(items[i]); // I see “database.db” here
}
})
.catch(err => {
console.log(err);
});

this.file.checkFile(this.file.applicationDirectory + ‘www/’, ‘database.db’) // FileError {code: 1, message: “NOT_FOUND_ERR”}
.then(entry =>{
console.log(‘ok’);
})
.catch(err => {console.log(err)});

The filename in your descriptive paragraph does not match the filename in the code.

Oh, I forgot to change it when writing this post. Thank you

Hi guys,
After so much trying, I found this solution to store images

    let realData = imagen.split(",")[1];
    let blob = this.b64toBlob(realData, 'image/jpeg');

    this.file.checkDir(this.file.externalApplicationStorageDirectory, 'DirectorioFotos')
        .then(_ => {
          this.file.writeFile(this.file.externalApplicationStorageDirectory + 'DirectorioFotos/', UUID + '.jpg', blob).then(response => {
            // ACTION
          }).catch(err => {
            // ACTION
          })
        })
        .catch(err => {
          this.file.createDir(this.file.externalApplicationStorageDirectory, 'DirectorioFotos', false).then(result => {
            this.file.writeFile(this.file.externalApplicationStorageDirectory + 'DirectorioFotos/', UUID + '.jpg', blob).then(response => {
              // ACTION
            }).catch(err => {
              // ACTION
            })
          })
        });
  b64toBlob(b64Data, contentType) {
    contentType = contentType || '';
    var sliceSize = 512;
    var byteCharacters = atob(b64Data);
    var byteArrays = [];

    for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
      var slice = byteCharacters.slice(offset, offset + sliceSize);

      var byteNumbers = new Array(slice.length);
      for (var i = 0; i < slice.length; i++) {
        byteNumbers[i] = slice.charCodeAt(i);
      }

      var byteArray = new Uint8Array(byteNumbers);

      byteArrays.push(byteArray);
    }

    var blob = new Blob(byteArrays, {type: contentType});
    return blob;
  }

I hope someone is helpful