I am getting this error FileError: {"code":1,"message":"NOT_FOUND_ERR"}
when i call this.file.readAsDataURL(directory, nameFile)
.
Error
Here my code:
selectFile() {
let options = {
quality: 100,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
saveToPhotoAlbum: false,
correctOrientation: true,
destinationType: this.camera.DestinationType.FILE_URI
};
if (this.isCordovaLib) {
this.showSpinner = true;
this.camera.getPicture(options).then((imagePath) => {
//"b71d96bbf34fe3c7d54b8e5a36d260c2.jpg"
let nameAndroidFile = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.lastIndexOf('?'));
//"e:///data/user/0/com.xxx.ionicframeworkapp/cache/b71d96bbf34fe3c7d54b8e5a36d260c2.jpg?1603481469382"
let nameIosFile = imagePath.substring(imagePath.lastIndexOf('tmp/') + 4, imagePath.length);
//"b71d96bbf34fe3c7d54b8e5a36d260c2.jpg"
let nameFile = this.platform.is('android') ? nameAndroidFile : nameIosFile;
console.log('nameFile', nameFile);
//"file:///storage/emulated/0/Android/data/com.xxx.ionicframeworkapp/cache/"
let directory = this.platform.is('android') ? this.file.externalCacheDirectory : this.file.tempDirectory;
// this.imagePath = this.webview.convertFileSrc(imagePath);
this.file.readAsDataURL(directory, nameFile).then(
file64 => {
console.log('including file');
this.showSpinner = false;
this.fileSelected['body'] = file64.substring(file64.indexOf('base64,') + 7, file64.length);
this.fileSelected['name'] = nameFile;
},
error => {
this.showSpinner = false;
console.log('error', error);
}
).catch(err => {
this.showSpinner = false;
console.log('error', err);
alert('Error accessing the file');
});
},
(err) => {
this.showSpinner = false;
});
}
}
What am I doing wrong in code? Please help me to solve my issue.
1 post - 1 participant