node.js - Google Cloud Print API - white page when printing PDF -


i want send pdf file printed using google cloud print api. code bellow give me positive message telling me 1 page generate. when go , check came out, gate empty page.

the same result happens if save print on google drive.

the code

unirest.post('https://www.google.com/cloudprint/submit') .header('authorization', 'bearer ' + token) .header("accept-charset", "utf-8") .field('xsrf', xsrf_token) .field('printerid', printerid) .field('ticket', '{"version": "1.0", "print": {}}') .field('title', 'test simpe.li') .field('contenttype', 'application/pdf') .attach('content', buffer) .end(function (res) {      console.log(res);  }); 

i know i'm sending pdf, because when change

.field('contenttype', 'application/pdf') 

to

.field('contenttype', 'text/plain') 

i 53 pages of text raw content of pdf file.

enter image description here

question

what i'm doing wrong?

tech spec

  • nodejs v4.1.1
  • unirest v0.4.2

it turns out google documentation left key information out. send binary type data, pdf, need convert file base64. in addition need tell google going send them base64 blob add field contenttransferencoding , set value base64.

another important thing. there bug in unirest (for nodejs @ least), sending base64 file won't set content-size header. nor setting own fix problem. circumvent issue had switch request. following code shows post google cloud print works:

let buffer64 = buffer.tostring('base64');  let formdata = {     xsrf: xsrf_token,     printerid: printerid,     ticket: '{"version": "1.0"}',     title: 'test print',     contenttransferencoding: 'base64',     contenttype: 'application/pdf',     content: buffer64 };  let headersdata = {     'authorization': 'bearer ' + token };  request.post({     url: 'https://www.google.com/cloudprint/submit',     headers: headersdata,     formdata: formdata }, function (err, httpresponse, body) {    if (err) {      return console.error('upload failed:', err);    }    console.log('upload successful!  server responded with:', body);  }); 

i hope others :)


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -