Using Javascript FileReader with Huge Files

I have a problem using Javascript FileRead while trying to read huge files.

For example, I have a 200 MB text file, and every time I read this file, the code stops working.

Is it possible to read a text file, but, for example, ONLY the first 10 lines or stop reading after 10mb?

This is my code:

var file = form.getEl().down('input[type=file]').dom.files[0]; var reader = new FileReader(); reader.onload = (function(theFile) { return function(e) { data = e.target.result; form.displayedData=data; }; })(file); reader.readAsText(file); 

e.target.result always contains all the data in the file.

What can i do here?

thanks

+7
javascript filereader onload
source share
1 answer

This will only read the first 10 mb:

 var file = form.getEl().down('input[type=file]').dom.files[0]; var reader = new FileReader(); reader.onload = function(e) { var data = e.target.result; form.displayedData = data; }; reader.readAsText(file.slice(0, 10 * 1024 * 1024)); 
+10
source share

All Articles