You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Postman Mock Server配置:如何设置含图片文件的GET响应?

How to Return Image Files in Postman Mock Server GET Responses

Got it, I’ve run into this exact issue before with Postman Mock Servers—since the response editor doesn’t offer a direct binary/form-data option, you need to use a couple of workarounds to get image files returned. Here’s how to implement both common solutions:

Method 1: Return Base64-Encoded Images Directly

This is the most reliable way to serve images directly from your mock server without relying on external hosts:

  • First, convert your image file to a Base64 string:
    • On Mac/Linux, use this Terminal command:
      base64 /path/to/your/image.jpg > image_base64.txt
      
    • On Windows, use this PowerShell command:
      [Convert]::ToBase64String((Get-Content -Path "C:\path\to\your\image.png" -Encoding Byte)) | Out-File -FilePath "image_base64.txt"
      
  • Open your target request in Postman, navigate to the Response tab for your Mock Server configuration
  • Switch to the Raw response mode, then go to the Headers section:
    • Add a Content-Type header with the correct value for your image (e.g., image/jpeg for JPGs, image/png for PNGs)
  • Paste the full Base64 string from your text file into the Raw response body field
  • Save the response configuration. When you send a request to your Mock Server, switch to the Preview tab—Postman will automatically decode the Base64 string and display the image.

Method 2: Redirect to a Hosted Image (Simpler for Public Images)

If your image is already hosted on a public, accessible URL, you can use a redirect instead:

  • In the Mock Server’s Response tab, set the response status code to 302 Found
  • Add a Location header to the response, with its value set to the full URL of your hosted image
  • Save the configuration. When you send a request to the Mock Server, it will redirect the request to the image URL, returning the image file directly.

Key Notes

  • For large images, Base64 encoding increases file size by ~33%, so the redirect method is more efficient in these cases
  • Double-check that your Base64 string has no extra spaces or line breaks—these can cause decoding failures
  • If you need dynamic image responses, you can combine Base64 with Postman’s Mock Variables to swap out strings based on request parameters

内容的提问来源于stack exchange,提问作者Kris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:12:04