Download PDF Node.js

Asked

Viewed 910 times

0

I’m using Request to download a billet from https://www.boletocloud.com/ which is in pdf. Turns out I can’t see the pdf I downloaded, the API developers say it’s in UTF-8, I’ve uploaded everything but it still doesn’t work.

request

app.get('/', function(req, res) {
    var options = { method: 'POST',
      url: 'https://sandbox.boletocloud.com/api/v1/boletos',
      headers:
       { 'content-type': 'application/x-www-form-urlencoded;',
         'postman-token': '058e9f74-644b-a03c-fc53-fbc46f3fe8b3',
         'cache-control': 'no-cache',
         'accept-charset': 'UTF-8',
         encoding: 'utf-8',
         authorization: 'Basic YXBpLWtleV9yODBfLVUyWHlWcjlsbFIwSXhMOUFGUkFRTnloUU11UF9SUnRZTmU1WnNjPTp0b2tlbg==' },
      form:
       { 'boleto.conta.banco': /* Outros campos... */ } };

    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      res.contentType("application/pdf; charset=utf-8");
      var utf8 = body.toString('utf8');
      res.send(utf8);
  });
  • 2

    Put the solution in a reply please, we are not a forum, understand the operation of the site: http://answall.com/tour

  • I would put as a response, however I understood that the recommendations was to respond. Anyway I will change here.

1 answer

0


Resovido using the pipe function.

request(options, function (error, response, body) {
  /* CODIGO */ 
}).pipe(res);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.