I'm using the checkFile function from File API plugin in Ionic 3 to check if a file exists locally. The Promise rejects with the following error :
FileError {code: 5, message: "ENCODING_ERR"}
From what I see on the Mozilla Docs of the File API, the problem is that "The URL is malformed." However, I don't see how is the URL malformed. Here is the relevant code showing how I'm calling the function plus the actual values of involved variables (The value of baseDirectory
is set to file:///data/user/0/ch.protectator.fehpedia/files/
) :
let baseDirectory = this.file.dataDirectory;
let fileToCheck = "File:Icon Portrait Abel.png";
let promise = this.file.checkFile(this.file.dataDirectory, fileName).then(bool => {
// Things
}, reason => {
console.error(reason);
});
And that's the Promise that fails. What's strange about that case is that I actually tried to display that image later in the code, ignoring if it has been found by File.checkFile, and the image displays.
In the HTML template, I later use :
<img [src]="imgUrl">
where imgUrl
is set using :
this.imgUrl = this.file.dataDirectory + '/' + "File:Icon Portrait Abel.png";
So the image exists and displays correctly when called by the WebView, but the Native File plugin tells me the URL is malformed, even to me it seems to be exactly the same URL. That's where I'm stuck, I don't know what to change for the code to work. Should checkFile
be used in a different way ? Also, a more precise cause of failure would help, but all I got is ENCODING_ERR
, I don't know what actual part of the URL seems malformed.
After looking through similar cases, I've found no solution nor documentation about this specific case. But while experimenting with different values, I found what caused this error : :
. Yes, the colon. The one present in the file name.
While I still have no explanation about why :
causes the native File
plugin to fail but not the web view, removing :
from the file name effectively allows File
to see it without raising an ENCODING_ERR
. While this is not an optimal solution, this workaround is effective.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With