:
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 a file.');
console.log(this.reader.error);
}
this.reader.onload = this.upload;
this.reader.onerror = this.error;
}
このコードは、次のコンソール出力を作成します。
このように静的に設定することにより、this
を追跡:
var _this = this; // _this won't change
this.reader.onerror = function() {
console.log('An error occurred while reading a file.');
console.log(_this.reader.error);
}
、やりますあなたは同じ問題がありますか? Chromeの代わりにFFを使用する場合は、同じ問題がありますか?そうでない場合は、Chromeの同じ起源のポリシーに踏み込んでいる可能性があります。ここでの答えとコメントを参照してください:http://stackoverflow.com/questions/4100927/chrome-filereader/4101266#comment10572715_4101266 –