title: Downloading File With Web API using Jquery Post
body: <p>I have a web Api function that returns a file stream</p>
  
  <pre><code>[HttpPost] 
  public HttpResponseMessage DownloadDocument([FromBody] parameters)
      {
          try
          {
              var stream = FileHelper.GetFilesStream(fileUrl);
              HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(stream) };
              result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
              result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
              result.Content.Headers.ContentDisposition.FileName = fileName;
              return result;
          }
          catch (Exception)
          {
              return Request.CreateErrorResponse(HttpStatusCode.NotFound, "File Not Found");
          }
      }
  </code></pre>
  
  <p>How can I call this method in Jquery Ajax to download the file so the save file dialog pops up. I am working with knockout.js, in click event handler of a button, I call this WebAPI method and I get the stream, but I don't know how to save it to the file.</p>