title: Downloading remote files using the Javascript file API
body: <p>Stemming from a lack of finding a download manager I like on Ubuntu, I was wondering if it's possible to create one using HTML5 and JavaScript with the new File API available in Chrome. At the moment I'm working on a proof of concept which will just download a small file (Google's logo) from a remote URL into the sandbox file system. Code below:</p>
  
  <pre><code>window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
  
  function onError(e) {
      console.log('Error:', e)
  }
  
  var xhr = new XMLHttpRequest();
  xhr.open('GET', 'https://www.google.co.uk/images/srpr/logo11w.png', true);
  xhr.responseType = 'blob';
  
  xhr.onload = function(e) {
  
      window.requestFileSystem(TEMPORARY, 1024*1024, function(fs) {
  
          fs.root.getFile('google.png', {create: true}, function(fileEntry) {
  
              fileEntry.createWriter(function(writer) {
  
                  var blob = new Blob([xhr.response], {type: 'image/png'});
  
                  writer.write(blob);
  
              }, onError);
  
          }, onError);
  
      }, onError);
  
  }
  
  xhr.send();
  </code></pre>
  
  <p>This seems like it'd work to me, however when running it won't allow me to download Google's logo due to <code>Access-Control-Allow-Origin</code>.</p>
  
  <p>Due to this being relatively new I haven't been able to find the <em>best</em> way to achieve what I want using the new file API functions, so I'm not even sure if using a AJAX request is the best way to do it. If not, I'm open to suggestions. Otherwise, is there a way to get around the <code>Access-Control-Allow-Origin</code> problem?</p>
  
  <p>I need to keep this 100% client side also, I can't use something like PHP to stream the file to the client or anything.</p>