Search code examples
base64postman

Postman display base64 image as test result


I am trying to visualize a base64 img I receive in my response using the Postman Test feature.

My JSON:

{
  ...,
  "result": {
    ...,
    "image": "data:image/jpeg;base64,/..."
  }
}

I want to do something like this:

let template = `
<img src='{{img}}'/>
`

pm.visualizer.set(template, { 
    img: pm.response.json().result.image
})

How can I display the base64 image inside the tag / retrieve it from the Postman pm object?


Solution

  • Your variant almost right, but you need to retrieve img data for the template in a proper way like following:

    let template = `
    <img src='{{img}}'/>
    `;
    
    pm.visualizer.set(template, { 
        img: pm.response.json()["result"]["image"]
    });