title: Forwarding a stream in c# api
body: <p>In my service we need to get a zip file created by another service and return it.</p>
  
  <p>This is my code (code has been simplified for the question):</p>
  
  <pre><code>[HttpGet("mediafiles/{id}")]
  public async Task&lt;IActionResult&gt; DownloadMediaFiles(int id)
  {
      var fileIds = _myProvider.GetFileIdsForEntityId(id); // result be like "1,2,3,4"
  
      using var httpClient = new HttpClient();
      var response = await httpClient.GetAsync($"http://file-service/bulk/{fileIds}");
      var stream = await response.Content.ReadAsStreamAsync();
  
      return File(stream, "application/octet-stream", "media_files.zip");
  }
  </code></pre>
  
  <p>With the <code>id</code> I can gather the info I need to create the <code>fileIds</code> string and call the other service.</p>
  
  <p>Here's the api on the other service (code has been simplified for the question):</p>
  
  <pre><code>[HttpGet("bulk/{idList}")]
  public async Task&lt;IActionResult&gt; DownloadBulk(string idList)
  {
      var ids = string.IsNullOrEmpty(idList) ? new List&lt;int&gt;() : idList.Split(',').Select(x =&gt; Convert.ToInt32(x));
  
      using var memoryStream = new MemoryStream();
      using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
      {
          var index = archive.CreateEntry("hello.txt");
          using (var entryStream = index.Open())
          using (var streamWriter = new StreamWriter(entryStream))
          {
              streamWriter.Write("hello");
          }
      }
  
      var byteArray = memoryStream.ToArray();
  
      return File(byteArray, "application/octet-stream", "media_files.zip");
  }
  </code></pre>
  
  <p>but when the client tries to open the zip we get</p>
  
  <blockquote>
    <p>Exception has occurred. ArchiveException (FormatException: Could not
    find End of Central Directory Record)</p>
  </blockquote>
  
  <p>I'm absolutely not confident about these two lines of the <code>/mediafiles/{id}</code></p>
  
  <pre><code>var stream = await response.Content.ReadAsStreamAsync();
  
  return File(stream, "application/octet-stream", "media_files.zip");
  </code></pre>
  
  <p>And probably the issue might be there.</p>
  
  <p>I just need to forward back the <code>file-service</code> response, but I don't know why</p>