title: How to consume spring StreamingResponseBody in Angular 8
body: <p>I have the following code in my springboot backend</p>
  
  <pre><code> @GetMapping(value = "/stream", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
      public ResponseEntity&lt;StreamingResponseBody&gt; stream() {
          File file = new File("C:\\test\\test.mp3");
          try {
              InputStream is = new FileInputStream(file);
              StreamingResponseBody resp = outputStream -&gt; {
                   IOUtils.copy(is, outputStream);
              };
              return ResponseEntity.ok()
              .contentType(MediaType.APPLICATION_OCTET_STREAM)
              .contentLength(file.length())
              .body(resp);
          } catch(Exception e) {
              e.printStackTrace();
          }
          return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
              .contentType(MediaType.APPLICATION_OCTET_STREAM)
              .body(null);
  
      }
  
  </code></pre>
  
  <p>I am trying to consume it in my angular app like this</p>
  
  <p><strong>HTML</strong></p>
  
  <p><code>&lt;p&gt;{{ content }}&lt;/p&gt;</code></p>
  
  <p><strong>Typescript</strong></p>
  
  <pre><code>ngOnInit(): void {
      const header = new HttpHeaders().set('Accept', 'application/octet-stream');
      this.http.get('http://localhost:8080/stream', {headers: header}).subscribe(
        (res: any) =&gt; {
          this.content = JSON.stringify(res);
        },
        (err: any) =&gt; {
          this.content = JSON.stringify(err);
        }
      );
    }
  </code></pre>
  
  <p>However unless I specify <code>responseType: 'text'</code> for the get method, I get only error. Also, I tried specifying responseType as blob and arraybuffer and specified several combinations of <code>observe: body|response|events</code>. Only <code>{}</code> is shown on the page. Not sure what is wrong here. </p>
  
  <p>I tried following <a href="https://stackoverflow.com/questions/53366704/angular-doesnt-download-a-file-from-a-stream-streamingresponsebody">this SO post</a> but not of much use.
  Can some one  please throw some light on it? Thanks in advance. </p>