I\'m trying to use the Cordova file plugin to read an image saved in a mobile device so I can then get the base64 encoding of it, which I need to store remotely. The problem
I discovered that this problem was related to Typescript. resolveLocalFilesystemUrl() was actually resolving with a File Entry object (when I passed it a local url as the file path), but Typescript thought it was an Entry object and didn't think file() could be called on it.
The below fixed the issue by telling Typescript that entry object could be of any type, so could have any function or property called on it.
MediaCapture.captureImage().then((images)=>{
self.image = images[0].localURL;
File.resolveLocalFilesystemUrl(self.image).then((entry: any)=>{
entry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function (encodedFile: any) {
var src = encodedFile.target.result;
src = src.split("base64,");
var contentAsBase64EncodedString = src[1];
};
reader.readAsDataURL(file);
})
}).catch((error)=>{
console.log(error);
})
})
Note that I also had to use encodedFile: any in order to allow target.result to be called on encodedFile