Cordova插件文件时出现EncodingError [英] EncodingError when cordova-plugin-file
问题描述
我现在正在开发一个以浏览器为平台的cordova应用程序.
I am now developing a cordova app which platform is browser.
我需要从本地文件系统访问文本文件,所以我正在使用cordova-plugin-file.
I need to access a text file from local file system, so I am using the cordova-plugin-file.
但是在我的chrome控制台中,异常失败了(没有CLI错误):
But I failed as the exception in my chrome console like this (There is no CLI error):
代码:5
code: 5
消息:提供给API的URI格式错误,或者结果数据URL超出了数据URL的URL长度限制."
message: "A URI supplied to the API was malformed, or the resulting Data URL has exceeded the URL length limitations for Data URLs."
名称:"EncodingError"
name: "EncodingError"
对我的代码造成打击:
document.addEventListener('deviceready', dataRead, false);
function dataRead() {
window.webkitRequestFileSystem(window.PERSISTENT, 100500*1024*1024, function() {
window.webkitResolveLocalFileSystemURL("filesystem:" + cordova.file.applicationDirectory + "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);
});
}
我的URI是否非法或出于其他原因?
Is my URI illegal or for some other reasons?
有人可以指出原因吗?或者给我看一个正确的例子.
Can anybody point out why? Or show me a right example.
感谢您的帮助.
推荐答案
文件插件的良好参考点是 cordova-plugin-test-framework 以及文件插件文档.
Good reference point for the file plugin are its auto and manual tests, which can be run in cordova-plugin-test-framework and also the file plugin documentation.
关于您的问题的几点:
- 尝试使用小于
100500*1024*1024
的内容,例如10*1024*1024
, - 代替
- try to use something less than
100500*1024*1024
, for example10*1024*1024
, - instead of
window.webkitResolveLocalFileSystemURL("filesystem:" + cordova.file.applicationDirectory + "1111.csv", gotFile, fail);
尝试使用
window.resolveLocalFileSystemURL("filesystem:" + cordova.file.applicationDirectory + "persistent/1111.csv", gotFile, fail);
这篇关于Cordova插件文件时出现EncodingError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!