如何通过nodejs请求发送pdf base64变量?

时间:2015-09-01 20:30:13

标签: node.js pdf requestjs

尝试发送带有请求的base64 pdf字符串,但我似乎无法弄清楚请求的正确结构。在此先感谢您的帮助!

    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)
  });

1 个答案:

答案 0 :(得分: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')