title: Download pdf file automatically using Angular Js
body: <p>I Have an API made using WEB API which gives a pdf file using type as HttpResponseMessage. </p>
  
  <p>This API is being called from a web application, which uses Angular Js.</p>
  
  <p>My problem is, i am not able to download the file when this API is called. It gives me corrupted file.</p>
  
  <p>Here is my WebAPI code</p>
  
  <pre><code>            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
              byte[] fileBytes = System.IO.File.ReadAllBytes(outputFilePath);
              response.Content = new ByteArrayContent(fileBytes);
              response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
              //response.Content.Headers.ContentDisposition.FileName = "Certificate#" + ideaModel.IdeaNumber + ".pdf";
              response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
  
              return new CertificateModel { file = response, fileName = "Certificate#" + ideaModel.IdeaNumber.ToString()+".pdf" };
  </code></pre>
  
  <p>In angular JS i am calling URL, and trying to save file using FileSaver.js</p>
  
  <pre><code>  $http.post(getUrl('api/Reward/DeliverGift'),
          {
              IdeaNumber: '4',
              SubmittedBy: 'Self',
          },{responseType: 'arraybuffer'}
      ).then(function (response) {            
          var certificateFile = new Blob([response.data.file], { type: 'application/pdf' });
          saveAs(certificateFile, response.data.fileName );
  
      }, function (errors) {         
      });
  </code></pre>
  
  <p>My original file is of 195Kb, however above code gives me a file of 9 bytes</p>