0

I'm trying to simply read the files under src/assets/data (I've created the data directory with some text files under it).

I've tried many ways without success:

this.file.resolveDirectoryUrl("/assets/data") // as well tested with "/www/assets/data" and "/www/assets/data/", with or without the front "/", as well with all those solutions with `this.file.applicationDirectory +` in front of the string
  .then(directoryEntry => {
    directoryEntry.createReader().readEntries(function (entries: Entry[]) {
      for (let entry of entries) {
        console.log(entry);
      }
    })
  });

and

this.file.resolveLocalFilesystemUrl(this.file.applicationDirectory+"assets/data/")

as well as what suggested another reply

(<any>window).resolveLocalFileSystemURL(this.file.applicationDirectory + "www/assets/data/",
  function (fileSystem) {
    fileSystem.createReader().readEntries(function (entries: Entry[]) {
      for (let entry of entries) {
        console.log(entry);
      }
    })
  },
  function (error) {
    console.error(error);
  }
);

For all those solutions I always end with te following error: "A URI supplied to the API was malformed, or the resulting Data URL has exceeded the URL length limitations for Data URLs."

I'm running cordova with ionic cordova run browser --port=8000 and this.file.applicationDirectory is equal to http://localhost:8000/

Does someone know how to do this simple thing? Or should I move my data folder in another place and use another API to simply read my local application files?

I'm using the following dependencies versions (among others) in my package.json:

"@angular/core": "5.0.3",
"@ionic-native/core": "4.4.0",
"@ionic-native/file": "^4.5.3",
"cordova-plugin-file": "^6.0.1",
"cordova-plugin-ionic": "3.0.0",
"cordova-browser": "~5.0.3"
Anthony O.
  • 22,041
  • 18
  • 107
  • 163

1 Answers1

0

applicationDirectory is not supported in browser platform, so it won't work there, you have to test in one of the supported platforms. (iOS, Android, Windows, OSX)

jcesarmobile
  • 51,328
  • 11
  • 132
  • 176