Partially load data from files via File API in Javascript

137 views Asked by At

With File API it is possible load data from local files into the browser memory via Javascript. I'm accessing huge files (200MB and bigger) on a system that is low in available RAM (webapp on an mobile device). How can I use the W3C File API (or Cordovas File Api as a fallback) to partially load data (e.g. by specifying a byte range) from files?

1

There are 1 answers

0
Sebastian Barth On

The solution is to use File.slice(). Notice that File inherits from Blob and thereby receives its slice() method.

var blob = file.slice(startingByte, endindByte);
reader.readAsBinaryString(blob);

Source of this information is HTML5Rocks.com. A full example can be found there.