【发布时间】:2015-06-13 03:21:33
【问题描述】:
我正在尝试在 Chrome 应用中使用文件系统 API。我已经尝试了所有可以找到的示例代码,但无法读取简单的文本文件。我几乎记录了每一步,似乎发生(或没有发生)的是我第一次引用文件读取器对象时一切都停止了。它创建得很好,因为我可以记录 .readyState,但之后我似乎什至无法设置 onload() 事件或执行 .readAsText()。
这是我通过按钮调用的内容:
function clickButton(){
chrome.fileSystem.chooseEntry({type: 'openFile', acceptsMultiple: false}, function(FileEntry){
if(chrome.runtime.lastError) {console.warn("Warning: " + chrome.runtime.lastError.message);}
else{
console.log(FileEntry);
var thing = new FileReader();
console.log(thing.readyState);
thing.onloadstart(function(){
console.log("Started loading " & FileEntry);
});
console.log("added onloadstart");
console.log(thing.readyState);
console.log(thing);
thing.readAsText(FileEntry);
console.log(thing.readyState);
console.log(thing.result);
}
});
document.getElementById("status").innerHTML = "I did something";
}
我确实在某处读到 Chrome 不允许访问本地文件,但 chrome 应用程序似乎有所不同。至少,文档似乎表明了这一点。
我在控制台中最终得到的唯一东西是 FileEntry 对象。
https://developer.chrome.com/apps/app_storage#filesystem
我已经使用了上面链接中的示例代码,但仍然无法正确使用。其他人有这个问题或知道我做错了什么?
【问题讨论】:
标签: google-chrome-app filereader