I have a totally Restless AngularJs + Node (Express) application. The back-end serves only to validate requests and route to other applications, which have business rules.
At the moment, my front sends a request to generate a pdf, something like:
const callbackSucesso = function(resposta){
if(resposta && resposta.data){
let headers = resposta.headers();
let blob = new Blob([resposta.data],{type: headers['content-type']} );
saveAs(blob, "download.pdf");
}else{
//coisas que não importam aqui
}
};
$http({
method: 'POST',
url: '/api/pdf',
data: JSON.stringify(dto)
}).then(callbackSucesso,callbackErro);
However, when I open the generated file, I notice that there is information that is distorted, for example: DESCRIPTION = > DESCRIPTION
When done by postman, the API return is normally generated as a file.
I've already found answers that tell you how to add type information to the Blob object - such as this: Generate angled pdf using javascript - but the error has been retained.
When I tried to do in the back end, the outputs were not very different. Then I thought about intercepting the node, generating the file, and redirecting it to the front.
const fs = require('fs');
...
request(options, function(error, resposta, corpo){
if(error) {
//não interessa para o contexto
}else{
fs.writeFileSync("10111.pdf", corpo,'binary');
//aqui eu enviaria o link pro front baixar
}
next();
});
I followed this example here: link
Thank you in advance to anyone who can clear my road (!)