PDF empty when downloading using Spring Boot and AngularJS

0

I'm creating an application where I need to return a PDF via an API call developed in Spring Boot through AngularJS, my code looks like the one below:

API Return:

ResponseEntity.ok()
        .headers(result.getHttpHeaders())
        .body(new InputStreamResource(result.getInputStream()));

Where the header is application / pdf

Angular CodeJS:

$http.get("path/pdf", 
    { params: params },
    { responseType: "arraybuffer" }
)
.then(function(response){
     console.log(response.data);
     var blob = new Blob([response.data], {type: 'application/pdf'});            
     FileSaver.saveAs(blob, 'arquivo.pdf');
});

As a result, the PDF generated by FileSaver is left blank, even the response.data , with the data being.

When calling the API url directly from the browser, the PDF is returned normally.

    
asked by anonymous 16.07.2018 / 22:09

1 answer

1

Problem solved by changing method in AngularJS :

$http.post(mobioneEnvService.addPath("/operation/report/alerts/export"), 
           params, 
           {responseType:"arraybuffer"})
     .then(function(response){

            var blob = new Blob([response.data], {type: 'application/pdf'});

            FileSaver.saveAs(blob, 'report.pdf');
     });

The API must also accept calls through POST.

    
16.07.2018 / 23:01