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
2 Answers
Reset to default 6You 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
评论列表(0条)