FileReader error: The object is already busy reading Blobs
阿新 • • 發佈:2022-03-09
在使用多個FileReader物件時候會遇到。
FileReader錯誤:物件已經忙於讀取Blob。
var blob = this.file.slice(this.readed, this.readed + this.step); this.reader.readAsArrayBuffer(blob);
解決方案:
reader讀取時候,先判斷一下readyState值,如果不是loading的話再執行讀取。
if (this.reader.readyState == 1) return;var blob = this.file.slice(this.readed, this.readed + this.step); this.reader.readAsArrayBuffer(blob);
readyState
FileReader
價值 | 狀態 | 描述 |
---|---|---|
0 |
EMPTY |
閱讀器已建立。尚未呼叫任何讀取方法。 |
1 |
LOADING |
已呼叫讀取方法。 |
2 |
DONE |
操作完成。 |
EMPTY
-
已
FileReader
建立,但尚未呼叫 readAs 方法。 LOADING
DONE
var reader = new FileReader(); console.log('EMPTY', reader.readyState); // readyState will be 0 reader.readAsText(blob); console.log('LOADING', reader.readyState); // readyState will be 1 reader.onloadend = function () { console.log('DONE', reader.readyState); // readyState will be 2 };
更多:
HTML5 檔案域+FileReader 分段讀取檔案並上傳(八)-WebSocket
HTML5 檔案域+FileReader 分段讀取檔案並上傳(七)-WebSocket