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 commented 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?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With