'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 1:[1]

Try console.log() on your template to see if it is resolving how you expect. I got your solution to work using a hard-coded base64 image of a little red dot

const base64ImgData = `data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
    AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
        9TXL0Y4OHwAAAABJRU5ErkJggg==`

const template = `
<img src="{{img}}">
`

pm.visualizer.set(template, {img: base64ImgData})

Screenshot

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Claire Froelich