angular 2 download pdf file with post

0

I have a api rest developed using springboot on the backend and angled as a front.

The rest code is:

@PostMapping("/imprimir/{id}")
@PreAuthorize("hasAuthority('ROLE_CADASTRAR_INSTRUCAO') and #oauth2.hasScope('write')")
public ResponseEntity<byte[]> imprimir(@PathVariable Long id) throws 
     Exception {
        byte[] relatorio = instrucaoService.imprimir(id); 

        return ResponseEntity.ok()
                .header(HttpHeaders.CONTENT_TYPE, 
                MediaType.APPLICATION_PDF_VALUE)
                .body(relatorio);
}

This code works perfectly in postman, but I can not succeed in angled code with the following code:

component.ts

imprimirInstrucao2(form: FormControl) {
    this.instrucaoService.imprimir(this.instrucao)
      .then(res => {
        const fileURL = URL.createObjectURL(res);
      })
      .catch(erro => this.errorHandler.handle(erro));
  }

service.ts

imprimir(instrucao: Instrucao): Promise<any> { 
    return this.http.post('${this.url}/imprimir/${instrucao.id}',
    {responseType: 'arraybuffer'})
      .toPromise()
      .then(response => response.arrayBuffer());
  }

Thank you in advance.

    
asked by anonymous 26.01.2018 / 20:35

0 answers