title: Angular2 excel file download via Spring boot
body: <p>I am trying to download excel file through connecting spring boot from angular2 . 
  My boot looks like below </p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET,value="/downloadExcel/{weekEnd}",produces=MediaType.APPLICATION_OCTET_STREAM_VALUE)
  public ResponseEntity  downloadLastWeekOOOData(@PathVariable String weekEnd,HttpServletRequest request,HttpServletResponse response) throws IOException{
  
  
      File result=new File("C:\\sayan\\poi-test.xls");
      String type=result.toURL().openConnection().guessContentTypeFromName("poi-test.xls");
      FileInputStream inputStream = new FileInputStream(new File("C:\\sayan\\poi-test.xls"));
      byte[]out=org.apache.commons.io.IOUtils.toByteArray(inputStream);
  
      HttpHeaders responseHeaders = new HttpHeaders();
      responseHeaders.add("content-disposition", "attachment; filename=" + "poi-test.xlsx");
      responseHeaders.add("Content-Type",type);
  
      ResponseEntity  respEntity = new ResponseEntity(out, responseHeaders,HttpStatus.OK);
      System.out.println(respEntity.getBody());
      return respEntity;
  </code></pre>
  
  <p>}</p>
  
  <p>angular2 code looks like :</p>
  
  <pre><code>downloadExcel(weekEnd: string) {
  let downloadSuccess: boolean = false;
  this.lastWeekOOOService.downloadExcel(weekEnd)
    .subscribe(blob =&gt; {
      var link = document.createElement('a');
      link.href = window.URL.createObjectURL(blob);
      link.download = "Report.xlsx";
      link.click();
    },
    error =&gt; console.log("Error downloading the file."),
    () =&gt; console.info("OK"));
  </code></pre>
  
  <p>}</p>
  
  <p>service looks like :</p>
  
  <pre><code>downloadExcelOOO(weekEnd:string): Observable&lt;Response&gt; {
      return this._http.get('http://localhost:8080/downloadExcel/'+weekEnd)
                  .map(res =&gt; new Blob([res],{ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }))
                  .catch(this.handleError);
  }
  </code></pre>
  
  <p>But I am getting a file Report.xlsx downloaded which is corrupted . </p>