Mock Server - Get Image / File Option

My question: I am using the Mock Server setup for very basic API calls, so as example sending through an order number and receiving back a text update such as “your order is due tomorrow”. This is fine and I have this working however, I would now like to be able to call product info and it come through either as an image or in file format such as a PDF. Really struggling to find any sort of sample to this being done previously. The best I have come up with is a simple API call, where it returns a random image link through the faker library - issue here is all I receive is a URL link and not the actual image which is my objective.

if someone can assist and provide screenshots of an example in Postman that would be really useful

2 Likes

We’re having the same issue so I thought I would add a reply here instead of starting my own thread.

We are using Postman to mock a 3rd party API. We uploaded the Open API specs and created mock servers and everything seems to work ok for REST and JSON.

What we can’t do is mock an endpoint that returns a PDF. I think the issue is that Postman example responses can only be text. There’s no such thing as “response types”, it’s just a raw text field. I think a PDF is not really representable as text i.e. you can’t just open it in Notepad and copy/paste the contents into the example response box.

Is there any way to return a file from a mock server?

Hi there,

I do have the same issue. Mocking API calls works great for JSON, but I can not save an example that has an image as response.
I’ve read that this is a limitation of Postman mocking server, it there a plan for releasing this feature?

Hey!
So if the response’s Content-Type header indicates that the response is an image, Postman will render the image automatically. I believe this also works for the application/pdf content type. Note however, these responses cannot be saved as an example.

When it comes to the preview window, due to iframe sandbox restrictions, JavaScript and images are turned off in the iframe. For these response types, you can select “Send and download” to save the response locally and view natively. This should also work for saving as an example and mocking.
Learning Center Link

With the visualizer, you can embed an image with the html <img> tag in your test script and view it under the visualizer tab.
Learning Center Link

Hope this answered your questions! :slight_smile: