问题解决了,阅读评论HTML5文件API:安全性错误时读取文件
第三个问题我与HTML5文件API: 我仍然使用Chrome 12在Mac OS X雪豹和我m仍然尝试使用HTML5 File API读取文件,但FileHandler.error()会因为出现“SECURITY_ERR”而被调用。 我尝试阅读的文件是来自桌面的常规.txt文件,但它不适用于其他文件,尽管我可以使用常规应用程序打开它们。
function FileHandler(files, action) {
console.log('FileHandler called.');
this.files = files;
this.reader = new FileReader();
this.action = action;
this.handle = function() {
console.log('FileHandler.handle called.');
for (var i = 0; i < this.files.length; i++) {
this.reader.readAsDataURL(files[i]);
}
}
this.upload = function() {
console.log('FileHandler.upload called.');
console.log(this.reader);
data = {
content: this.reader.result
}
console.log(data);
}
this.error = function() {
console.log('An error occurred while reading the file.');
console.log(this.reader.error);
}
this.reader.onload = this.upload.bind(this);
this.reader.onerror = this.error.bind(this);
}
的代码生成以下控制台输出: http://cl.ly/1x1o2F0l2m3L1T2c0H0i
问题解决了!我只是将脚本上传到了一个完美的web空间。 –
如果您正在从'file://'测试应用程序,则可以使用以下标志运行Chrome:'--allow-file-access-from-files --allow-file-access'。这应该只用于测试目的。 – ebidel
@ebidel您应该添加该评论作为答案,所以这篇文章可以关闭:) –