获取小于2GB的文件没问题,但是当我选择大于2GB的跨度时,什么也不会输出。
<input type="file" name="vf" id="vf">
<span id="fileprecent"></span>
<script>
function byid(e){ return document.getElementById(e); }
function mc(e){ return Math.ceil(e); }
var vf=byid("vf");
var fpercent = byid("fileprecent");
vf.addEventListener( "change", () => {
var fr = new FileReader();
var chunk = [];
fr.addEventListener( "loadend",frLoadEnd );
fr.addEventListener( "progress",frProgress );
function frLoadEnd( e ){
var dataURL = e.target.result;
var dataLength = e.target.result.length;
var chunkSize = ( dataLength/100 );
for( var i = 0; i < 100; i++ ){
var lastChunk = ( chunkSize*( i+1 ) );
var firstChunk = ( lastChunk-chunkSize );
chunk.push( dataURL.slice( firstChunk,lastChunk ) );
}
}
function frProgress( e ){
var percent = Math.round( ( e.loaded/e.total )*100 );
fpercent.textContent = ( percent + " % Loaded" );
}
fr.readAsDataURL( vf.files[0] );
} );
</script>
javascript错误
(索引):22未捕获的TypeError:无法读取null的属性'length' 在FileReader.frLoadEnd