-
Notifications
You must be signed in to change notification settings - Fork 5.8k
PhantomJS 2.0 webserver module response.setEncoding("binary") not working #13026
Comments
I can also confirm that this is true. Multiple hours were spent wondering why examples wouldn't work so thank you @lweigand :D. Works fine on 1.9.8 on Windows. |
Confirmed this is broken. (ubuntu, compiled Phantom2 from source). |
Confirmed in windows. It worked with version 1.9.8. The pdf file downloaded from response cannot be opened, Adobe Reader says it is damaged. I also found version 2.0 generates large PDF than 1.9.8 for same page. |
It looks like the content is encoded to UTF-8 - something that doesn't happen with 1.9.7 - then it gets truncated to the length before the encoding, so the end of the file is lost. |
+1 big bummer |
confirmed on mac, too downgrading to phantomjs 1.9.8 helped solving this issue |
Same here. Any workarounds to avoid downgrading? |
@marcosbrigante we pushed the encoding down into the client, i.e. in the response handler from phantom did something like this: var binaryString = new Buffer(response).toString('utf-8');
return new Buffer(binaryString, 'binary'); |
@griffinmyers thanks I will give it a try. My current workaround is to use base64 instead of binary to transfer the pdf. But it requires decoding on the client... response.setHeader('Content-type', 'application/base64');
response.write(btoa(fs.read('test.pdf', 'b'))); |
QVariantHelper expects body to be the same type as before conversion. If target type doesn't match the source type, QVariantHelper will return 0. We can't convert in this way: QString > QVariant -> QByteArray Instead we must use the following way: QString > QVariant -> QString Fixes: ariya#13026
QVariantHelper expects body to be the same type as before conversion. If target type doesn't match the source type, QVariantHelper will return 0. We can't convert in this way: QString > QVariant -> QByteArray Instead we must use the following way: QString > QVariant -> QString Fixes: ariya#13026
For anyone still stuck here, please try this work around. Thanks for @marcosbrigante and all other posts. PhantomJS script:
Server side [C#]:
|
Is there a timeline, when this will be released? |
QVariantHelper expects body to be the same type as before conversion. If target type doesn't match the source type, QVariantHelper will return 0. We can't convert in this way: QString > QVariant -> QByteArray Instead we must use the following way: QString > QVariant -> QString Fixes: ariya#13026
I'm still having trouble with this, even with 2.1. Is that ".toLatin()" conversion right? |
@rcarmo yes. It works. Just tested it. |
for me, this:
Is still failing under 2.1. Trying to figure out why the webserver doesn't like it... |
In an old version(2.0.0-windows), setEncoding('binary') doesn't work.but rsp.setEncoding('latin1') works. I update to the 2.1.1-windows, setEncoding('binary') works too. So you can use setEncoding('latin1') if you don't want to update at once. |
In phantomjs 2.0, calling
setEncoding("binary")
on the response object has no effect. What was working fine with version 1.9.7_1 now seems to be broken.Code to replicate (where test.pdf may be any other binary file in the directory of the script):
I am running on Mac OSX 10.10.
The text was updated successfully, but these errors were encountered: