0

I have a get connection that with retrieve the photo of a student and it has the student id, though the image retrieved is on base64, can I export this automatically to jpg as part of my initial postman get script,so I request the photos and export and save them to jpg

I am completely new to Postman and Javascript.

I have created a GET Command that get the student photo, it comes back with the image in base64. I also have the student ID number, so I need to be able to save the base64 code to jpg with the student ID, ie 123456.jpg

How can I do this?

Output of postman command

enter image description here

James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

You can't save to disk directly from a PostMan script. I would recommend the following work flow:

Before you work with Postman:

  1. Create a local web server (in any language but Node.js would be one choice) and a POST-route to which you can send the base64-code and the id as your request body.
  2. Let the server convert this to a 'blob' and save to disk with the id as file name.
  3. Start the web server (for example on port 3000).

In PostMan:

  1. Create a collection with two requests
  2. Let the first request go to the URL/route you that returns the student id and base64-encoded image.
  3. Store each one (id and base64-encoded image data) in two separate environment variables in the your test-script.
  4. Create the second request to your local web server.
  5. In the request body send the two environment variables.

I don't know if you are familiar with writing backend-code/web-servers but this is the best solution I can come up with.

If you don't know how environment variables, scripting or collections work in Postman - look it up Postman's documentation which is very well written.

Thomas Frank
  • 1,404
  • 4
  • 10