title: Angular Spring Boot File Download
body: <p>Good day to you reading this!</p>
  
  <p>I did the upload functionality on this software setup but I cannot finish the download part...
  Digged as much as I could around here and this is where I got so far.</p>
  
  <p>My code looks like this:</p>
  
  <p><strong>Server</strong></p>
  
  <pre><code> @GetMapping(value = "/projects/file/download/{filename}/{projectId}")
   public ResponseEntity&lt;byte[]&gt; getResource(@PathVariable String filename, @PathVariable Long 
      projectId,HttpServletResponse response) throws ResourceNotFoundException, IOException {
  
      String fileLocation=//a location that I set, removed logic to make this shorter
  
      File downloadFile= new File(fileLocation);
  
      byte[] isr = Files.readAllBytes(downloadFile.toPath());
      String fileName = filename;
      HttpHeaders respHeaders = new HttpHeaders();
      respHeaders.setContentLength(isr.length);
      respHeaders.setContentType(new MediaType("text", "json"));
      respHeaders.setCacheControl("must-revalidate, post-check=0, pre-check=0");
      respHeaders.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + fileName);
      return new ResponseEntity&lt;byte[]&gt;(isr, respHeaders, HttpStatus.OK);
  
   }
  </code></pre>
  
  <p><strong>Angular Service</strong></p>
  
  <pre><code>downloadFile(filename: string, projectId: number): Observable&lt;any&gt; {
   return this.http.get(`${this.baseUrl}/file/download/` + filename + '/' + projectId, { responseType: 'blob' });
  }
  </code></pre>
  
  <p><strong>Angular Component</strong></p>
  
  <pre><code>downloadFile(fl: FileModel) {
    //calling service
    this.projectSerivce.downloadFile(fl.fileName, this.id).subscribe(response =&gt; {
      window.open(response.url, '_blank');
    });
  }
  </code></pre>
  
  <p>It reaches server and comes back and then a new blank browser tab is open and nothing else happens.. No error whatsoever. </p>