Reputation: 1
I am developing a hybrid app targeting iOS & Android. I had to implement a photo-uploader so I implemented it through ImagePicker
& File
Cordova Plugins. I tested it on Android and everything was okay.
The problem is when I test it for iOS I get the image URIs through ImagePicker
but File
throws the following error:
[error] - ERROR Error: Uncaught (in promise):
FileError: {"code":5,"message":"ENCODING_ERR"}
I have seen plenty of issues related to this error but all of them are related to Android while I have a problem with iOS. I understand that is a really complex issue so if anyone could give me any piece of advice, I would be grateful.
More details about the issue:
this.imagePicker
.getPictures({
maximumImagesCount: 1,
})
.then(async (result : string[]) => {
let file = 'file://' + result[0];
let path = file.substring(0, file.lastIndexOf("/") + 1);
this.image = await this.file.readAsDataURL(path, file): // Line which throws the exception
});
PS: I've tried adding 'file://' in all the ways I could imagine =)
Thanks in advance
Upvotes: 0
Views: 622
Reputation: 1
Thanks both of you who helped, I fixed my problem through changing the outputType to 1 (base64 dataURL) instead of 0 (URI).
This is the code that fixed my bug.
this.imagePicker
.getPictures({
outputType: 1,
})
.catch((e) => alert(e))
.then(async (results: string[]) => {
this.image = "data:image/jpg;base64," + results[0]
}
});
A posible explanation for this is that ImagePicker is copying from the ios gallery directory to a ImagePicker's temporary directory, then File is trying to read those copied files but they must have been deleted by iOS File System.
Upvotes: 0