【发布时间】:2015-12-17 07:15:58
【问题描述】:
我现在正在开发一个科尔多瓦应用程序,其平台是浏览器(Chrome)。
使用 cordova-plugin-file 读取文件失败。
根据cordova-plugin-file : Chrome quirks的文档,它说:
Chrome 文件系统在设备就绪事件后未立即就绪。作为一种解决方法,您可以订阅filePluginIsReady 事件....您可以使用window.isFilePluginReadyRaised 函数来检查是否已经引发了事件。
我的代码是这样写的:
document.addEventListener('deviceready', dataRead, false);
function dataRead() {
window.addEventListener('filePluginIsReady', readyToRead, false);
console.log(window.isFilePluginReadyRaised());
}
function readyToRead(){
window.initPersistentFileSystem(10*1024*1024, function() {
var fs = cordova.file.applicationDirectory;
console.log(fs);
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory + "www/1111.csv", gotFile, fail);
},function (e) {
console.log(e);
});
}
function fail(e) {
console.log("FileSystem Error");
console.dir(e);
}
function gotFile(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
console.log("Text is: "+this.result);
}
reader.readAsText(file);
});
}
读取文件失败,控制台消息如下:
为文件添加代理 ------------------cordova.js:942
授予永久 fs 配额 ---------Preparing.js:170
false --------------------------------------app.js:4(值为
window.isFilePluginReadyRaised())
似乎filePluginIsReady 事件没有触发!为什么?
此外,如果我直接在deviceready 事件下编写代码。它也会失败并显示以下错误消息:
代码:5
消息:“提供给 API 的 URI 格式不正确,或者生成的数据 URL 已超出数据 URL 的 URL 长度限制。”
名称:“编码错误”
谁能指出原因或给我一个正确的例子?
感谢任何帮助。
【问题讨论】:
-
我也有同样的问题。你找到解决办法了吗?谢谢。
-
关闭cordova运行浏览器打开的Chrome实例重启后终于可以使用了
标签: cordova google-chrome cordova-plugins html5-filesystem cordova-plugin-file