Search code examples
angularjscordovaionic-frameworkngcordova

Cordova plugin file readAsText error


I'm using ngCordova cordova-plugin-file to try to read an image that I then want to convert to bytes. I actually want to read it as dataURL and I'm getting an error.

/* The image is located at file:///data/data/com.xxx.housekeeping/cache/tmp_Screenshot_2017-04-27-09-30-42-1816635709.png on an Android device */
$cordovaFile.readAsText(cordova.file.cache, "tmp_Screenshot_2017-04-27-09-30-421403920141.png")
      .then(function (success) {
        // success
        console.log(success);
      }, function (error) {
        // error
        console.log(error);
      });

I tried using both readAsText and readAsDataURL but I get

Wrong type for parameter "uri" of resolveLocalFileSystemURI: Expected String, but got Undefined.

as an error. This is on an Android device.

Is there something I'm missing or doing wrong?


Solution

  • Should be cacheDirectory, was accessing the wrong location

    $cordovaFile.readAsText(cordova.file.cacheDirectory, "tmp_Screenshot_2017-04-27-09-30-421403920141.png")
          .then(function (success) {
            // success
            console.log(success);
          }, function (error) {
            // error
            console.log(error);
          });