javascript - Return binary result from phantomjs webserver - Stack Overflow

Is there any way to return result froma PhantomJS webserver as binary?To be more specific, If I render

Is there any way to return result froma PhantomJS webserver as binary?

To be more specific, If I render a screenshot of a page as base64, can I then transform this base64 string into binary and return it so the client receives it as an image?

This is what I have so far, I've mented out some of my experiments which apparently doesnt work

response.statusCode = 200;
response.setHeader("Content-Type", "image/png");
//response.setHeader("Content-Encoding","base64");
var base64 = page.renderBase64('png');
//var binary=atob(base64,"b");
response.write(base64  );
response.close();       

Ideas?

Is there any way to return result froma PhantomJS webserver as binary?

To be more specific, If I render a screenshot of a page as base64, can I then transform this base64 string into binary and return it so the client receives it as an image?

This is what I have so far, I've mented out some of my experiments which apparently doesnt work

response.statusCode = 200;
response.setHeader("Content-Type", "image/png");
//response.setHeader("Content-Encoding","base64");
var base64 = page.renderBase64('png');
//var binary=atob(base64,"b");
response.write(base64  );
response.close();       

Ideas?

Share Improve this question asked Aug 12, 2013 at 7:08 Roger JohanssonRoger Johansson 23.2k18 gold badges105 silver badges204 bronze badges 1
  • Have you got any progress on the issue? – naneri Commented Oct 13, 2016 at 19:57
Add a ment  | 

2 Answers 2

Reset to default 6

You can just set the Encoding to binary, and it will work:

response.statusCode = 200;
response.headers = {
    'Cache': 'no-cache',
    'Content-Type': 'image/png'
};
response.setEncoding('binary');
response.write(atob(page.renderBase64('png')));
response.close();

The solution is to use binary encoding in webserver module and page.evaluate inside web page module to generate binary content.

the result is something like this (assuming page is defined) :

response.statusCode = 200;
response.setEncoding("binary");
response.setHeader("Content-Type", "image/png");
var base64 = page.renderBase64('png');
var binary = page.evaluate(function (data) { return atob(data, "b");}, base64);
response.write(binary)
response.close();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744751508a4591624.html

相关推荐

  • javascript - Return binary result from phantomjs webserver - Stack Overflow

    Is there any way to return result froma PhantomJS webserver as binary?To be more specific, If I render

    20小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信