Ionic 3 Native:文件:{code:5,消息:& quot; ENCODING_ERR& quot;} [英] Ionic 3 Native : File : {code: 5, message: "ENCODING_ERR"}

查看:92
本文介绍了Ionic 3 Native:文件:{code:5,消息:& quot; ENCODING_ERR& quot;}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ionic 3中来自File API插件的 checkFile函数检查文件是否在本地.Promise拒绝并出现以下错误:

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 {代码:5,消息:"ENCODING_ERR"}

FileError {code: 5, message: "ENCODING_ERR"}

根据我在文件API的Mozilla文档,问题在于"URL格式不正确".但是,我看不出URL的格式如何.这是相关代码,显示了我如何调用该函数以及所涉及变量的实际值( baseDirectory 的值设置为 file:///data/user/0/ch.protectator.fehpedia/files/):

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);
});

这就是失败的承诺.这种情况的奇怪之处在于,我实际上试图稍后在代码中显示该图像,而忽略了File.checkFile是否找到了该图像,并显示了该图像.

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.

在HTML模板中,我稍后使用:

In the HTML template, I later use :

<img [src]="imgUrl">

其中使用

imgUrl 进行设置:

this.imgUrl = this.file.dataDirectory + '/' + "File:Icon Portrait Abel.png";

因此,该图像存在并在被WebView调用时正确显示,但是Native File插件告诉我URL格式错误,甚至对我来说它似乎是完全相同的URL.那就是我被困住的地方,我不知道为使代码正常工作需要进行哪些更改.是否应该以其他方式使用 checkFile ?另外,更精确的失败原因会有所帮助,但是我得到的只是 ENCODING_ERR ,我不知道URL的实际部分似乎格式错误.

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.

尽管我仍然没有关于为什么 的解释:导致本机 File 插件失败,但不会导致Web视图失败,因此删除了:文件名中的有效地允许 File 看到它而无需提出 ENCODING_ERR .虽然这不是最佳解决方案,但此解决方法很有效.

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.

这篇关于Ionic 3 Native:文件:{code:5,消息:&amp; quot; ENCODING_ERR&amp; quot;}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆