1

I read very large files using FileReader:

reader.readAsDataURL(bigFile);

Whenever the load ends I do the following:

reader.addEventListener('load', () => {
    myGlobalFile = {data:reader.result, type:reader.file.type};
});

Setting up myGlobalFile = {data:reader.result, type:reader.file.type}; can take some time and blocks actions of my user.

How can I set up the variable in a non-blocking way? Can I make use of FileReader progress to slowly add chunks to my variable?

Nate
  • 7,606
  • 23
  • 72
  • 124
  • Some more information would be helpful. What kind of data is it? What actions can the user do to that data without all of it? – Trobol Dec 23 '18 at 14:42
  • The user can upload any file...the user doesn't do anything with the data. I don't want to upload the data to the server before the user submit it. – Nate Dec 23 '18 at 15:19
  • Sorry, I misunderstood your question. Maybe try a Web Worker to handle the file? [This question may help](https://stackoverflow.com/questions/33306015/pass-submited-file-to-web-worker-by-refference-with-as-little-overhead-as-possib) – Trobol Dec 23 '18 at 15:31
  • Have you tried using a setTimeout with ‘0’ to read the file? I would at least try using setTimeout on the callback. – Rafiek Dec 23 '18 at 15:42

0 Answers0