0
I am creating an application where I need to return a PDF through an API call developed in Spring Boot through Angularjs, my code is like the below:
Return of the API:
ResponseEntity.ok()
.headers(result.getHttpHeaders())
.body(new InputStreamResource(result.getInputStream()));
Where the header is application/pdf
Code Angularjs:
$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 empty, even the sponse.date., with the data.
When calling the API url directly from the browser the PDF is returned normally.
Ever tried to change the
responseType
forblob
and call straightFileSaver.saveAs(response, 'arquivo.pdf')
orFileSaver.saveAs(response.data, 'arquivo.pdf')
?– Jéf Bueno
Yes already tried, Filesaver.saveAs receives an instance of Blob when changing an error happens, and changing only responseType the pdf keeps coming blank.
– Caio