title: .NET Core 2.0 Web API for Video Streaming from FileStream
body: <p>I have found a bunch of examples that use objects not available to me within my application and don't seem to match up to my version of .NET Core web API. In essence I am working on a project that will have <code>&lt;video&gt;</code> tags on a web page and want to load the videos using a stream from the server rather than directly serving the files via a path. One reason is the source of the files may change and serving them via path isn't what my customer wants. So I need to be able to open a stream and async write the video file.</p>
  
  <p>This for some reason produces JSON data so that's wrong. But I just don't understand what I need to do to send a streamed video file to a <code>&lt;video&gt;</code> tag in HTML.</p>
  
  <p>Current Code:</p>
  
  <pre><code>[HttpGet]
  public HttpResponseMessage GetVideoContent()
  {
      if (Program.TryOpenFile("BigBuckBunny.mp4", FileMode.Open, out FileStream fs))
      {
          using (var file = fs)
          {
              var range = Request.Headers.GetCommaSeparatedValues("Range").FirstOrDefault();
              if (range != null)
              {
                  var msg = new HttpResponseMessage(HttpStatusCode.PartialContent);
                  var body = GetRange(file, range);
                  msg.Content = new StreamContent(body);
                  msg.Content.Headers.Add("Content-Type", "video/mp4");
                  //msg.Content.Headers.Add("Content-Range", $"0-0/{fs.Length}");
                  return msg;
              }
              else
              {
                  var msg = new HttpResponseMessage(HttpStatusCode.OK);
                  msg.Content = new StreamContent(file);
                  msg.Content.Headers.Add("Content-Type", "video/mp4");
                  return msg;
              }
          }
      }
      else
      {
          return new HttpResponseMessage(HttpStatusCode.BadRequest);
      }
  }
  </code></pre>