0

Trying to send a base64 pdf string with request, but I can't seem to figure out the proper structure of the request. Thanks in advance for the help!

    var dpdf = pdfvar.toString('base64');

    var options = {
    method: 'POST',
    body: dpdf,
    url: FILEPICKER_URL,
    headers: [
      {
        name: 'content-type',
        value: 'application/pdf'
      }
    ]
  };

  request(options, function(err, httpResponse, body){ 
    console.log('body: ', body);
    console.log('code ', httpResponse.statusCode)
  });
user3527354
  • 586
  • 1
  • 7
  • 20
  • Are you getting an error? – Yuri Zarubin Sep 01 '15 at 20:40
  • Yes, the resulting pdf file sent to filepicker is a corrupted file. But I know dpdf is fine bc I emailed it as an attachment through mandrill and it worked fine. – user3527354 Sep 01 '15 at 20:54
  • The problem is something with the options object but I'm not sure what. Whether I need to include it as a json object or include another header field...not sure. – user3527354 Sep 01 '15 at 20:55

1 Answers1

0

The other side is expecting a PDF

application/pdf

and not a BASE64 representation of it.

Anyway, looking at what you are trying to do, without necessarily understanding how you are trying to do it... I would try and append a data url compatible header to your string like so :

var dpdf = 'data:application/pdf;base64,' + pdfvar.toString('base64')
k1dbl4ck
  • 176
  • 1
  • 7
  • to provide greater context, I am trying to replace a file uploaded via filepicker.io. I am doing that via post request but need to figure out how to send the pdf – user3527354 Sep 02 '15 at 02:28