title: Converting IRestResponse to "image/jpg" File
body: <p>I'm trying to pull an image from an API and return to the DOM through the <code>File()</code> method.</p>
  
  <p>Here's what I have so far..</p>
  
  <p><code>HomeController.cs</code>:</p>
  
  <pre><code>public class HomeController : Controller
  {
      public ActionResult Index()
      {
          return View();
      }
  
      public ActionResult ImageFromPath()
      {
          var client = new RestClient("http://{{MYIPADDRESS}}/cgi-bin/snapshot.cgi?channel0=");
          var request = new RestRequest(Method.GET);
          request.AddHeader("postman-token", "random-postman-token");
          request.AddHeader("cache-control", "no-cache");
          request.AddHeader("authorization", "Digest username=\"MYUSERNAME\", realm=\"MYENCRYPTEDPASS\", nonce=\"LONGSTRING\", uri=\"/cgi-bin/snapshot.cgi?channel0\", response=\"RESPONSESTRING\", opaque=\"\"");
          IRestResponse response = client.Execute(request);(response.RawBytes);
  
          return File(response, "image/jpg");
      }
  }
  </code></pre>
  
  <p>The only problem here, is that the error on the return statement, <code>response</code> shows </p>
  
  <blockquote>
    <p>cannot convert from 'RestSharp.IRestResponse' to 'byte[]'</p>
  </blockquote>
  
  <hr>
  
  <p>When I was pulling the image from the local file system, it was easier and worked, here was my working code for <code>HomeController.cs</code></p>
  
  <pre><code>public ActionResult ImageFromPath(string path)
  {
      var ms = new MemoryStream();
      using (Bitmap bitmap = new Bitmap(path))
      {
          var height = bitmap.Size.Height;
          var width = bitmap.Size.Width;
  
          bitmap.Save(ms, ImageFormat.Jpeg);
      }
  
      ms.Position = 0;
      return File(ms, "image/jpg");
  }
  </code></pre>
  
  <p>Here's how I was pulling it in my front end (<code>Index.cshtml</code>):</p>
  
  <pre><code>&lt;img src="@Url.Action("ImageFromPath", new { path = Request.MapPath("~/img/1.jpg") })" /&gt;
  </code></pre>