Thursday 7 January 2021

NOT_FOUND_ERR while trying to load Ionic file as blob from android device

I am getting a FileError {code: 1} while trying to load a file from my android device using cordova-plugin-file. My code:

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

private loadGpkgBlob(): Promise<any> {
  const gpkgPath = this.file.externalRootDirectory + "test_dir/test.gpkg";

  return new Promise((resolve, reject) => {
    return this.file.resolveLocalFilesystemUrl(gpkgPath).then((fileEntry: any) => {
      fileEntry.file(gpkgFile => {
        // file is present (see screenshot 1)
        console.log("gpkgFile: ", gpkgFile);

        const reader = new FileReader();

        reader.onloadend = function (e) {
          const blob = new Blob([reader.result], { type: 'application/geopackage+sqlite3' });
          // blob with size 4 (see screenshot 2)
          console.log("result: ", blob);
          resolve(blob);
        };

        reader.onerror = function (e) {
          // FileError {code: 1} -> NOT_FOUND_ERR (https://developer.mozilla.org/en-US/docs/Web/API/FileError)
          console.log("error: ", reader.error);
        };

        reader.readAsArrayBuffer(gpkgFile);
      });
    }).catch(e => e => console.log(e));
  });
}

Screenshot 1 - file on the device:

enter image description here

Screenshot 2 - gpkg-blob:

enter image description here

The file is obviously found. Any suggestions on how to fix/debug this?



from NOT_FOUND_ERR while trying to load Ionic file as blob from android device

No comments:

Post a Comment