My code is fairly standard:
// #csvfile is an input element with type="file"
var selectedFile = document.getElementById("csvfile").files[0];
var file = window.URL.createObjectURL(selectedFile);
fetch(file)
.then(response => response.text())
.then(text => {...})
It works reliably on all browsers for small files. However, in Chrome and Edge response.text()
returns an empty string ""
when I try to load a 671 MB CSV file. Firefox has no issue loading this file using the same code.
I've tried changing the fetch options (mode: "same-origin"
and headers: {"Content-Type": "text/plain"}
). Honestly, I'm just scrambling here because I don't know enough about JavaScript or the Fetch API to understand what else to try.
My intuition is that it has something to do with Firefox waiting an appropriate amount of time to resolve the promise in full whereas Edge and Chrome are terminating before the full stream is read into memory. I would appreciate some hints about how to test this theory since I'm fresh to the concept of promises in JavaScript.