PDF binary to base64

Hello @bear,
I want to convert a binary pdf to base64 to be able to see it in stoplight.

Here’s the scenario :

"scenarios": {
    "todo-crud": {
      "name": "Todo CRUD",
      "steps": [
          "type": "http",
          "name": "",
          "input": {
            "method": "get",
            "url": "http://www.archeonavale.org/pdf/cordeliere/test.pdf"
          "after": {
            "script": "\noutput.body.set('<object data=\"data:application/pdf;base64,'+Base64.encode(output.body.get())+'\" type=\"application/pdf\" width=\"100%\" height=\"100%\"/>')"

With a simple BTOA on NodeJS and passing the file by the binary method on postman it’s working.

We have a difference between the body size displayed and the body size in the var output.body.get() …

Hi Stoplight team,

The real problem here is that the body length doesn’t match with the value of the “Content-Length” header.

With the example given by Killian :

  • “Content-Length” header ==> 21742
  • console.log(output.body.get().length) ==> 21397

So the body has been altered and thus it’s impossible to deal with it in any sort (either Base64 or anything else).

Perhaps Thomas @bear has an idea about this behaviour and how to go beyond?
Any help would be appreciated.

@ntiss / @killian.hascoet give me a day or two to look at this.

When you look at it in the Rendered HTML Viewer, does it not work?

With the simple script we have we get a partial working solution because the PDF is not rendered correctly.
Here’s what we have with stoplight.

Here’s the real pdf :

It could be a new feature to display the pdf when stoplight receive a raw pdf data.

@killian.hascoet I will look at this in my spare time on a weekend. Will keep you updated.

Hi @bear
Any new about this ? It’s important for our company.
Perhaps should I create a case in your customer support portal if you need time on your work time?
Let me know what you prefer.

Yeah, please put it in the customer support portal, that would be helpful. I haven’t had chance to look at this.


Thanks @bear. Issue opened. Seen also with @ross

Hi @killian.hascoet, @ntiss, we just pushed a fix for this issue to our production environment. Can you try again and let us know if you continue to see issues here?

Hi @ross
I’m sorry but it doesn’t work at all. It’s even worse because nothing happens now when I choose “Rendered HTML” in the output section, and I get an error when click elsewhere in the UI :

(this GIF has been recorded with your hosted Next Plateform)

Hum… Things are not so simple.
I tried your last release onPremise, and I don’t reproduce the issue above. So the crash seems to be related to the app component 4.10.8. (I use 4.10.7 on Prem).

Better, the PDF testing works without needing to encode in Base64.
So your fix in Prism works on Premise, thank you very much. But you have a new bug on you hosted version.