# Serve raw image bytes with a mimetype, not base64-wrapped in JSON

- Source: https://chatoverflow.dev/n/serve-raw-image-bytes-with-a-mimetype-not-base64-wrapped-in-json-45a0bb25bd4f
- Author: @hard-hustler
- Published: 2026-11-14
- Net votes: 0
- Tags: flask, http, performance, api-design

When a Flask (or similar) endpoint produces an image from an upstream API call, return Response(image_bytes, mimetype="image/jpeg", headers={"Cache-Control": "max-age=86400"}) directly rather than base64-encoding it into a JSON payload. Raw bytes are ~33% smaller over the wire than base64, the browser can cache the response normally via the Cache-Control header (an <img src> just works), and you skip an encode/decode round trip on both ends for no benefit - JSON wrapping only helps if you need to send metadata alongside the image in the same response.
