I'm using FileReader API to read multiple files and breaking into parts
<p>I want to load multiple large large files. to do this I pinched the code from </p>

<blockquote>
  <p><a href="http://stackoverflow.com/questions/14438187/javascript-filereader-parsing-long-file-in-chunks">javascript FileReader - parsing long file in chunks</a></p>
</blockquote>

<p>Each chunk is given a part number and passed to a Python CGI program also give the total number of chunks to expect. The Python CGI concatenates the chunks  when the full set of chunks are received into the desired file. 
This works.</p>

<p>Now I want to load multiple files with each file broken into chunks as before. Each file has an id number so Python will know to store it in a different directory however I run out of memory and it crashes.
In</p>

<blockquote>
  <p><a href="http://stackoverflow.com/questions/13975031/reading-multiple-files-with-javascript-filereader-api-one-at-a-time">Reading multiple files with Javascript FileReader API one at a time</a></p>
</blockquote>

<p>There are suggestion how to convince Javascript to process one file at a time sequentially rather than asynchronously but my attempts to get this code to work with my current code have been unsuccessful.</p>

<p>The file splitting code is below. The variable numparts terminates the recursive call.</p>

<p>Can anyone suggest how to modify the code intended by the loop at the bottom to execute setupReader sequentially please.</p>

<pre><code> function setupReader(file,filename) {
    var fileSize = (file.size - 1);
    var chunkSize = 150000000;
    var offset     = 0;
    var numparts= Math.ceil(fileSize/chunkSize);
    var chunkReaderBlock = null;
    var partno=0;
    var readEventHandler = function(evt) {
       if (evt.target.error == null) {
           offset += chunkSize;
           callback(evt.target.result); // callback for handling read chunk
       } else {
           console.log("Read error: " + evt.target.error);
           alert("File could not be read");
           return;
       }
       if (partno &gt;= numparts) {
           console.log("Done reading file");
           return;
       }
       chunkReaderBlock(offset, chunkSize, file);
    }

    callback=function(result) {
       partno+=1;
       var bfile = result;
       var query="?fileName="+filename+"&amp;Part="+partno+"&amp;of="+numparts+"&amp;bfile="+bfile;
      loadDoc('partition0',query,0);
   }

   chunkReaderBlock = function(_offset, length, _file) {
      var r = new FileReader();
      var blob = _file.slice(_offset, length + _offset);
      r.onload = readEventHandler;
      r.readAsDataURL(blob);
   }
   chunkReaderBlock(offset, chunkSize, file);
 }

 for (var i = 0; i &lt; numfiles; i++) {
    setupReader(fileList[i],fileList[i].name);
</code></pre>

<p>I don't know python but isn't there a streaming solution to handle large file uploads?
Perhaps like this: <a href="http://stackoverflow.com/questions/2502596/python-http-post-a-large-file-with-streaming">Python: HTTP Post a large file with streaming</a> ?</p>

<p>In that case splitting the hole file into chunks and making multiple range request gets pointless</p>

javascript python