title: Download Google Drive file from url and send with post to backend
body: <p>I am trying to download a file from an url (chrome drive file) in javascript; and want to send it to my backend (php - laravel).</p>
  
  <pre><code>var url = file.downloadUrl !== undefined ? file.webContentLink : file.exportLinks['application/pdf'];
  
  console.log(url) // if I go to url, it downloads the file
  
  if (url !== undefined) {
        var remote = new XMLHttpRequest();
        remote.open('GET', url);
        remote.setRequestHeader('Authorization', 'Bearer ' + gapi.client.getToken().access_token);
        remote.setRequestHeader('Access-Control-Allow-Origin', '*');
        remote.onload = function(e) {
            vm.handle_download(remote.responseText, file, 200); // do something with the fetched content;
        };
        remote.onerror = function(e) {
               vm.handle_download('error response', null, remote.statusText);
        };
        remote.send();
  } else vm.handle_download('no downloadable url', {
       file: null,
       status: 'error'
  });
  </code></pre>
  
  <p>and on handle</p>
  
  <pre><code>handle_download: function (content, file, status) {
          if (status !== 200) {
              console.log('error occured on status')
              return;
          }
  }
  </code></pre>
  
  <blockquote>
    <p>Failed to load <a href="https://drive.google.com/uc?id=1D12321ofd4CNG-m9_Mp4aiDcnibNf&amp;export=download" rel="nofollow noreferrer">https://drive.google.com/uc?id=1D12321ofd4CNG-m9_Mp4aiDcnibNf&amp;export=download</a>: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://test.dev" rel="nofollow noreferrer">http://test.dev</a>' is therefore not allowed access.</p>
  </blockquote>