I have a really strange problem with getting local file data on android with ionic-framework.
Situation: I have a file that was earlier created on the path file:///data/user/0/app-id/files/my-folder/xyz.json
I can find the file inside the "adb shell", I also checked the data inside with cat and everything is fine. Over the Android-Studio File-Browser I also checked the file.
With the native file plugin '@ionic-native/file/ngx' I can also confirm, that the file is there.
const jsonFile = "pathToFile";
this.file.resolveLocalFilesystemUrl(jsonFile).then(fileEntry => {
console.log(fileEntry.nativeURL);
}).catch(err => {
console.log(err);
});
Result:
filesystem: FileSystem {name: "files", root: DirectoryEntry}
isDirectory: false
isFile: true
It also resolves the other stuff correct eg. name, fullPath, nativeURL
Now the problem starts, because I can't finde a way to get the data.
this.file.readAsText('', jsonFile).then(fileData => {...
this.file.readAsDataURL('', jsonFile).then(fileData => {...
this.file.readAsBinaryString('', jsonFile).then(fileData => {...
this.file.readAsArrayBuffer('', jsonFile).then(fileData => {...
All of them result in a {code: 5, message: "ENCODING_ERR"}
I also tried to get the data with the native http-plugin, with fetch and a normal http angular request...
Everything results in a cors, 404 etc.
So all in all, how can I get json-data from a local path that points to file:///data/user/0/app-id/files/...
ionic info:
Ionic:
Ionic CLI : 5.4.2 (xxxx/.npm-packages/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.10.0
@angular-devkit/build-angular : 0.801.3
@angular-devkit/schematics : 8.1.3
@angular/cli : 8.1.3
@ionic/angular-toolkit : 2.0.0
Cordova:
Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.1.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.2, (and 7 other plugins)
Utility:
cordova-res : 0.7.0
native-run : 0.2.8
System:
Android SDK Tools : 26.1.1 (xxxx/Library/Android/sdk)
ios-deploy : 1.9.4
NodeJS : v12.10.0 (/usr/local/Cellar/node/12.10.0/bin/node)
npm : 6.11.3
OS : macOS Mojave
Xcode : Xcode 11.0 Build version 11A420a