# Convert base64 code in the body to jpg file in the Postman script

**URL:** <https://community.postman.com/t/convert-base64-code-in-the-body-to-jpg-file-in-the-postman-script/47304>\
**Category:** Help Hub\
**Created:** [May 10, 2023, 12:26pm UTC](https://community.postman.com/t/convert-base64-code-in-the-body-to-jpg-file-in-the-postman-script/47304 "2023-05-10T12:26:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianharry](https://avatars.discourse-cdn.com/v4/letter/b/da6949/32.png) [@brianharry](https://community.postman.com/u/brianharry)\
**Post date:** [May 10, 2023, 12:26pm UTC](https://community.postman.com/t/convert-base64-code-in-the-body-to-jpg-file-in-the-postman-script/47304/1 "2023-05-10T12:26:59Z")

</div>

I have a get command that I use to get the photo of a student and then retrieve the photo. I have the student ID as part of teh response back ad the image as base64, how can I convert the base code for the image as a jpg and download automatically, as part of my initial get GET script, or can you recommend another solution to use .

I have tried using this script on the TEST Tab and I got the following message

console.log("PhotoId: " + pm.response.json()[“photoId”]);  
console.log("Base64: " + pm.response.json()[“photo”]);

//output in visualize tab  
let template = `<img src='{{img}}'/>`;

pm.visualizer.set(template, {  
img: `data:image/jpeg;base64,${pm.response.json()["photo"]}`  
});

Error Message

There was an error in evaluating the test script: JSONError: Unexpected token ‘\<’ at 1:1 \<?xml version="1.0" encoding="UTF-8"?\> ^

 ![Output1](https://us1.discourse-cdn.com/getpostman/original/3X/0/9/09419d2630c558e89782ed4503839e1a582421ee.jpeg)

Can you please help
