Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All files reads gave a error code 5; ENCODING_ERR in latest release on Android #289

Closed
domingosl opened this issue Jan 16, 2019 · 14 comments

Comments

@domingosl
Copy link

How to replicate the issue

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
    fs.root.getFile(cordova.file.applicationDirectory + "www/index.html", { }, function (fileEntry) {
       //DO NOTHING
    }, function(err) {
      console.log("error accesing the file", err);
    });

  }, function error(err) {
    console.log("error requesting the filesystem", err);
  });

This outputs:

error accessing the file FileError {code: 5}

The file exists, it is a Cordova project, and it also shows by doing:

function listDir(path){
  window.resolveLocalFileSystemURL(path,
    function (fileSystem) {
      var reader = fileSystem.createReader();
      reader.readEntries(
        function (entries) {
          console.log(entries);
        },
        function (err) {
          console.log(err);
        }
      );
    }, function (err) {
      console.log(err);
    }
  );
}

listDir(cordova.file.applicationDirectory + "www/index.html");

This shows that the file is present.

@alex-steinberg
Copy link

alex-steinberg commented Feb 14, 2019

I'm getting the same issue, except using Ionic. It works perfectly on iOS. cordova-plugin-file-opener2 2.1.4 and using com.android.support:support-v13:26.+ (not v4 due to a plugin conflict).

Opening the file:

this.fileOpener.open('file:///android_asset/www/assets/pdf/mypdf.pdf', 'application/pdf')
        .then(() => console.log('File is opened'))
        .catch(e => console.log('Error opening file', e));
// Error opening file {status: 9, message: "File not found"}

Checking that the file exists:

this.file.checkFile(path, filename)
        .then(result => console.log('File exists ', result))
        .catch(e => console.log('Problem checking file ', e));
// Problem checking file {code: 5, message: "ENCODING_ERR"}

Ionic info:

Ionic:

   ionic (Ionic CLI)  : 4.1.2
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.1.4, ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 1.2.1, (and 15 other plugins)

System:

   Android SDK Tools : 26.1.1 (~/Library/Android/sdk)
   ios-deploy        : 2.0.0
   NodeJS            : v8.12.0 (~/.nvm/versions/node/v8.12.0/bin/node)
   npm               : 6.4.1
   OS                : macOS
   Xcode             : Xcode 10.1 Build version 10B61

@haroondilshad
Copy link

Any solutions to this yet?

@Benji1
Copy link

Benji1 commented Mar 29, 2019

@domingosl @alex-steinberg @RonCan
Try this:

const justTheNameOfTheFile = "file.txt";
window.requestFileSystem(window.LocalFileSystem.PERSISTENT, 0, async fs => {
      window.resolveLocalFileSystemURL(window.cordova.file.dataDirectory, async dirEntry => {
          dirEntry.getFile(justTheNameOfTheFile, { create: true, exclusive: false }, fileEntry => {
                 // what you want to do
            }
      });
});

It is because window.cordova.file.dataDirectory returns file:///data/user/0/... and .getFile checks if there is a : in the string and throws the encoding error then. But with the solution above it worked for me.

@janpio
Copy link
Member

janpio commented Jun 7, 2019

What version of this plugin and version of Android does this affect?

@jfoclpf
Copy link

jfoclpf commented Jun 20, 2019

I know github here is not for help, but can someone help here?
https://stackoverflow.com/questions/56674724/apache-cordova-resolvelocalfilesystemurl-function-always-return-error-5-encod
It's the same issue

@QuentinIcky
Copy link

8 months later... always the same issue...

@crapthings
Copy link

crapthings commented Feb 12, 2020

hello this is 2020, works with ios sim, but not real device

@alex-steinberg
Copy link

FYI I'm migrating my app to Capacitor, really enjoying it so far. It has removed all the headaches associated with Cordova. Most native functionality you'd need is native to Capacitor (like file system). Highly recommended.

@mirko77
Copy link

mirko77 commented Feb 4, 2021

FYI I'm migrating my app to Capacitor, really enjoying it so far. It has removed all the headaches associated with Cordova. Most native functionality you'd need is native to Capacitor (like file system). Highly recommended.

Yeah...after Adobe running away, Cordova does not cut it anymore

@fbl773
Copy link

fbl773 commented Jun 17, 2021

Is Cordova dead? Seriously, their sqlite plugin is broken, I've been trying to write to a file all day, and nothing I try works. Not impressed.

@mirko77
Copy link

mirko77 commented Jun 17, 2021

Is Cordova dead? Seriously, their sqlite plugin is broken, I've been trying to write to a file all day, and nothing I try works. Not impressed.

Give Capacitor a try

@necrodamus
Copy link

necrodamus commented Sep 24, 2021

@domingosl @alex-steinberg @RonCan
Try this:

const justTheNameOfTheFile = "file.txt";
window.requestFileSystem(window.LocalFileSystem.PERSISTENT, 0, async fs => {
      window.resolveLocalFileSystemURL(window.cordova.file.dataDirectory, async dirEntry => {
          dirEntry.getFile(justTheNameOfTheFile, { create: true, exclusive: false }, fileEntry => {
                 // what you want to do
            }
      });
});

It is because window.cordova.file.dataDirectory returns file:///data/user/0/... and .getFile checks if there is a : in the string and throws the encoding error then. But with the solution above it worked for me.

Hi guys i am having a error anybody how to fix ? thanks
Asyc function not working, only work with this but i have a different error , i check permission but the problem apears is in android >10

window.requestFileSystem(window.LocalFileSystem.PERSISTENT, 0, function() {
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory+"Pictures", function(dirEntry) {
console.log(dirEntry);
dirEntry.getFile("IMG_20210924_102017.jpeg", { create: true, exclusive: false }, function(fileEntry) {
console.log(fileEntry);
fileEntry.remove(function (file) {

      console.log("file removed!");
  }, function (error) {
      
      console.log("error occurred: " + error.code);
  }, function () {
      
      console.log("file does not exist");
  });
    })

});
});
But i have error 6
NO_MODIFICATION_ALLOWED_ERR: 6
error occurred: 6
image

@xs2coder
Copy link

@domingosl @alex-steinberg @RonCan Try this:

const justTheNameOfTheFile = "file.txt";
window.requestFileSystem(window.LocalFileSystem.PERSISTENT, 0, async fs => {
      window.resolveLocalFileSystemURL(window.cordova.file.dataDirectory, async dirEntry => {
          dirEntry.getFile(justTheNameOfTheFile, { create: true, exclusive: false }, fileEntry => {
                 // what you want to do
            }
      });
});

It is because window.cordova.file.dataDirectory returns file:///data/user/0/... and .getFile checks if there is a : in the string and throws the encoding error then. But with the solution above it worked for me.

What is the use of "fs" in second line? Do we really need it?

@breautek
Copy link
Contributor

getFile expects a filename not a file path.

It's intended (for either reading or creating) to get the inside the DirectoryEntry.

Please see the examples for valid usages.

@breautek breautek closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests