Ionic 3 Native:文件:{code:5,message:" ENCODING_ERR"} [英] Ionic 3 Native : File : {code: 5, message: "ENCODING_ERR"}

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

问题描述

我正在使用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 {code:5,message:ENCODING_ERR}

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

从我在文件API的Mozilla文档,问题是网址格式错误。但是,我不知道URL是如何格式错误的。下面是相关代码,显示我如何调用函数加上涉及变量的实际值( baseDirectory 的值设置为文件:/ //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 使用以下方式设置:

where imgUrl is set using :

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.

虽然我仍然没有解释为什么 导致本机文件插件失败,但没有网页视图,从文件名中删除有效地允许文件查看它而不提出 ENCODING_ERR 。虽然这不是最佳解决方案,但这种解决方法很有效。

While I still have no explanation about why : causes the native File plugin to fail but no 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,message:&quot; ENCODING_ERR&quot;}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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