title: Return file in ASP.Net Core Web API
body: <h2>Problem</h2>
  
  <p>I want to return a file in my ASP.Net Web API Controller, but all my approaches return the <code>HttpResponseMessage</code> as JSON.</p>
  
  <h2>Code so far</h2>
  
  <pre><code>public async Task&lt;HttpResponseMessage&gt; DownloadAsync(string id)
  {
      var response = new HttpResponseMessage(HttpStatusCode.OK);
      response.Content = new StreamContent({{__insert_stream_here__}});
      response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
      return response;
  }
  </code></pre>
  
  <p>When I call this endpoint in my browser, the Web API returns the <code>HttpResponseMessage</code> as JSON with the HTTP Content Header set to <code>application/json</code>.</p>