title: C# - Downloading from Google Drive in byte chunks
body: <p>I'm currently developing for an environment that has poor network connectivity. My application helps to automatically download required Google Drive files for users. It works reasonably well for small files (ranging from 40KB to 2MB), but fails far too often for larger files (9MB). I know these file sizes might seem small, but in terms of my client's network environment, Google Drive API constantly fails with the 9MB file.</p>
  
  <p>I've concluded that I need to download files in smaller byte chunks, but I don't see how I can do that with Google Drive API. I've read <a href="https://developers.google.com/drive/v3/web/manage-downloads#partial_download">this</a> over and over again, and I've tried the following code:</p>
  
  <pre><code>// with the Drive File ID, and the appropriate export MIME type, I create the export request
  var request = DriveService.Files.Export(fileId, exportMimeType);
  
  // take the message so I can modify it by hand
  var message = request.CreateRequest();
  var client = request.Service.HttpClient;
  
  // I change the Range headers of both the client, and message
  client.DefaultRequestHeaders.Range =
      message.Headers.Range =
      new System.Net.Http.Headers.RangeHeaderValue(100, 200);
  var response = await request.Service.HttpClient.SendAsync(message);
  
  // if status code = 200, copy to local file
  if (response.IsSuccessStatusCode)
  {
      using (var fileStream = new FileStream(downloadFileName, FileMode.CreateNew, FileAccess.ReadWrite))
      {
          await response.Content.CopyToAsync(fileStream);
      }
  }
  </code></pre>
  
  <p>The resultant local file (from <code>fileStream</code>) however, is still full-length (i.e. 40KB file for the 40KB Drive file, and a 500 Internal Server Error for the 9MB file). On a sidenote, I've also experimented with <code>ExportRequest.MediaDownloader.ChunkSize</code>, but from what I observe it only changes the frequency at which the <code>ExportRequest.MediaDownloader.ProgressChanged</code> callback is called (i.e. callback will trigger every 256KB if <code>ChunkSize</code> is set to 256 * 1024).</p>
  
  <p>How can I proceed?</p>