'File Download Error(service angular spring boot) [closed]

downloading files with angular8 and spring boot. Spring boot service part worked with Postman. But when I download with angular, I get an error.error

It does not appear in the console.log ("File response:", response) section.

 downloadFile(event) {
        this.additionalDocumentService.getFileDownload(event.fileId).subscribe(response => {
          console.log("File response:",response)
          this.downloadFile = response;
    
          
        });
      }
      

   getFileDownload(fileId: number): Observable<any> {
    return this.http.get(apiHost + '/downloadFile/' + fileId);

  }

@RequestMapping("/downloadFile/{dosyaId}")
        public ResponseEntity<HttpStatus> handleFileDownloadPage(HttpServletRequest request, HttpServletResponse response, @PathVariable(value = "fileId") Integer fileId) throws IOException, Exception {
    
           
            File file = fileService.getFileId(fileId);
            
            if (StringUtils.hasText(dosya.getFilePath())) {
    
                ServletOutputStream out = response.getOutputStream();
    
                InputStream stream = null;
                try {
    -
                    stream = new FileInputStream(file.getFilePath());
                   
                    int bytesRead = 0;
                    byte[] buffer = new byte[8192];
                    response.setContentType("application/octet-stream");
                    response.setHeader("Content-Disposition", String.format(" attachment; filename=\"%s\"", file.getFileName()));
    
                    while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
                        out.write(buffer, 0, bytesRead);
                    }
                    out.flush();
    
                } catch (Exception e) {
                    System.err.println(e.toString());
                } finally {
                    out.close();
                    if (stream != null) {
                        stream.close();
                    }
                }
                return null;
    
            }
            return ResponseEntity.ok(HttpStatus.OK);
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source