問題を読みながら、HTML5ファイルAPI:セキュリティエラー解決ファイル
私はHTML5ファイルAPIを持っている第三の問題のコメントを読んで: を私はまだのMac OS X Snow Leopardの上のクロム12を使用し、I」私はまだHTML5 File APIでファイルを読み込もうとしていますが、 "SECURITY_ERR"が発生するためFileHandler.error()が呼び出されます。 私が読もうとするファイルは、デスクトップからの通常の.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
問題が解決しました。私はちょうど完全に動作するウェブスペースにスクリプトをアップロードしました。 –
'file://'からアプリをテストする場合は、 '--allow-file-access-from-files --allow-file-access'というフラグを付けてChromeを実行できます。これは、テスト目的でのみ使用してください。 – ebidel
@ebidelこの投稿を回答として追加して、この投稿を閉じることができるようにしてください:) –