title: Angular 2 downloading a file: corrupt result
body: <p>I am attempting to download a file using Angular 2/TypeScript and Web API. The problem I am having is that when downloading the text file, the file is file but when attempting to download an PDF file, for example, it is corrupted. The contents of the downloaded file is garbled nonsense.</p>
  
  <p>The TypeScript I am using is as follows:</p>
  
  <pre><code>downloadFile(fileId: string): Observable&lt;File&gt; {
      this.applicationsUrl = `${APIConfig.BaseUrl}/documents/download/${fileId}/`;
  
      let headers = new Headers({ 'Content-Type': 'application/json', 'MyApp-Application' : 'AppName' });
      let options = new RequestOptions({ headers: headers });
  
      return this.http.post(this.applicationsUrl, '', options)
          .map(this.extractContent)
          .catch(this.handleError);
  }
  
  private extractContent(res: any) {
      let blob: Blob = new Blob([res._body], { type: 'application/pdf'});
      window['saveAs'](blob, 'test.pdf');
  }
  </code></pre>
  
  <p>The window['saveAs'] is just a workaround to access the JavaScript FileSaver.js functions.</p>
  
  <p>Additionally I have set res:Response to res:any so I can access the private _body property under JavaScript without a compile failure in TypeScript.</p>
  
  <p>Any help would be greatly appreciated.</p>