Return the image file itself as the HTTP response body, and set Content-Type to the format actually in that body—for example, image/png, image/jpeg or image/webp. For a client whose main result is an image, raw bytes are usually simpler than wrapping the image in JSON as base64. The framework-specific example below shows the pattern in ASP.NET Core; the same HTTP principle applies across frameworks.
What an image response contains
An image response is an ordinary HTTP response whose body contains the image’s bytes. The response status indicates whether the request succeeded, and the Content-Type header tells the client what kind of representation the body contains.
HTTP/1.1 200 OK
Content-Type: image/png
<PNG bytes>
Do not serialize a byte array as ordinary JSON and assume the client will recognize it as an image. Return the bytes or a readable stream through your framework’s file, byte, or stream response helper. Set the media type to match the actual encoded file, not the format you hoped to generate.
- PNG bytes:
image/png - JPEG bytes:
image/jpeg - WebP bytes:
image/webp
The media type describes the representation; it does not convert the file. If your image encoder produces JPEG bytes but your endpoint labels them image/png, correct the encoding or correct the header.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Return bytes or a stream in your framework
Load or generate the image, then pass its bytes or stream to the framework’s response API. Framework helper names differ, so use the helper documented for the framework and version you deploy rather than copying an example from another stack.
ASP.NET Core Minimal API
In ASP.NET Core, TypedResults.File can return either a byte[] or a Stream; it sets the response content type, and accepts a filename when you want a download disposition. This example assumes GetImageBytes() is your own method that supplies valid PNG bytes:
app.MapGet("/image", () =>
{
byte[] imageBytes = GetImageBytes();
return TypedResults.File(imageBytes, "image/png");
})
.Produces<Stream>(contentType: "image/png");
The file result handles the response body; the OpenAPI metadata describes it to tools and API consumers. Microsoft’s ASP.NET Core guidance notes that a file-result return type does not automatically provide all response metadata for OpenAPI, so declare the response explicitly as appropriate for your application and framework version. For binary content, the documented schema representation uses a binary schema, with Stream recommended for that mapping.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Controller-based ASP.NET Core applications can use the controller file-result overloads for a byte array or stream, supplying the content type. The Minimal API code above is not portable verbatim to unrelated frameworks.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsOther frameworks
Look for the framework’s response helper that accepts bytes, a file, or a stream and a content type. Avoid returning an object that the framework will JSON-serialize unless your intended contract is JSON containing encoded image data. For large images or images already stored as files, a stream can avoid holding an additional full copy in memory; confirm the helper’s buffering and lifetime requirements for your framework.
Document the response in OpenAPI
OpenAPI describes response representations by media type. In OpenAPI 3.1.2, a PNG binary response can be documented with the media type and an empty schema:
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
responses:
'200':
description: Image bytes
content:
image/png: {}
The OpenAPI 3.1.2 specification uses image/png: {} as an example of an image returned as a binary file. Document the actual type your endpoint sends; if one operation can return multiple image formats, include each supported representation. For other OpenAPI versions and tooling, verify that version’s binary schema convention. OpenAPI 3.0 examples commonly express binary content as type: string with format: binary.
Document known error responses as well as success. A consumer should be able to distinguish an image response from a JSON error or other failure response without assuming that every request returns image bytes.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Choose raw image bytes, base64 JSON, or an image URL
| Response design | Use it when | Trade-off |
|---|---|---|
| Raw image bytes | The request’s main result is the image and the client can accept a binary response. | Direct to consume as an image, but the client must handle a binary body rather than expect JSON. |
| Base64 in JSON | The API contract needs to return image data together with structured metadata in one JSON value, or an intermediary requires a text representation. | Encoding expands the payload and clients must decode it. Base64 is not a general HTTP requirement. |
| JSON metadata with an image URL | The image should be fetched independently, reused across records, or accompanied by structured metadata. | The client makes a separate fetch and the API must define how that URL is made available and used. |
OpenAPI can describe either JSON or image media types; it does not dictate which of these designs an application should choose. Decide based on the client contract, reuse and caching needs, metadata requirements, and any infrastructure between the API and the client.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Account for gateways and serverless adapters
A correct application response can still be altered or rejected by a gateway or integration layer. Check binary handling along the entire request path, not just the code that creates the image.
AWS documents a specific case for API Gateway REST APIs using Lambda proxy integration: the function response is base64-encoded and the API’s binary media types must be configured for binary payloads. In that documented REST API behavior, API Gateway’s binary response handling depends on configuration, integration type, Content-Type, and the request’s Accept header; it honors only the first Accept media type. This AWS-specific behavior is not a universal rule for ordinary API servers. If this integration is in your path, check its binary media type configuration and the ordering of the client’s Accept values.
Test the response as a client will receive it
- Call the endpoint with a representative request and check the HTTP status.
- Inspect
Content-Typeand verify it matches the actual image file format. - Save or decode the response body as bytes and open it with an image viewer or parser; do not judge success from a non-empty response alone.
- Test an error case and confirm the client can tell an error response from the successful image response.
- If a gateway or serverless adapter is involved, repeat the test through that deployed path, including the intended request
Acceptheader.
For a download rather than inline display, set a suitable Content-Disposition filename through the framework helper. If the client should display the image normally, do not add a download disposition unnecessarily.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Conditional requests, ranges, caching, and cost
File-oriented response helpers can support HTTP file behavior beyond sending the bytes. In ASP.NET Core, file results can handle conditional and range requests when configured. Supplying validators such as ETag or Last-Modified can allow a client with an unchanged copy to receive 304 Not Modified with no body. These behaviors depend on the framework configuration and the validator supplied; they are not automatic properties of every image endpoint.
For large or frequently fetched images, consider whether streaming, caching, validators, or range support fit the use case. Test the behavior through any proxy or gateway that may buffer or transform the response. Avoid claiming a cache hit or reduced transfer unless you have verified the deployed path.
Troubleshoot common image-response failures
- The browser shows gibberish or downloads unexpectedly: check whether the response should be rendered inline or downloaded, and whether a download-oriented
Content-Dispositionwas set. Verify the response content type and actual body. - The client says the image is corrupt: inspect the body for a JSON-serialized byte array, encoded text, or an HTML error page. Confirm the bytes form a valid file and the declared format matches them.
- The response is JSON even though the endpoint returns bytes: the framework may be serializing the result as an object. Use the framework’s file, byte, or stream response helper instead.
- The OpenAPI page shows no image response: add explicit response metadata for the successful media type and use the binary schema convention that matches your OpenAPI version and tooling.
- It works locally but fails behind API Gateway: for AWS REST API Lambda proxy integrations, check binary media type configuration, the integration’s base64 requirements, and the first value in the request’s
Acceptheader. - Unchanged images are still transferred: if conditional caching is appropriate, supply validators such as
ETagorLast-Modifiedand verify that the framework and intermediary honor them.
Or skip the browser setup
If the image you need is a screenshot of a webpage, ScreenshotNeo returns a PNG, JPEG, WebP, or PDF from one GET request. Its API can return screenshot image bytes directly; see the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
- Cookie and consent banners, newsletter popups, and chat widgets are removed before the shot.
- Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed.
- An MCP server lets AI agents use the
take_screenshot,get_page_info, andcapture_pdftools. - The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.
Sign up for ScreenshotNeo’s free plan to start with 1,000 screenshots a month and no card.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Frequently Asked Questions
Can an API return a JPEG or WebP instead of PNG?
Yes. Return the actual JPEG or WebP bytes and declare the matching media type, such as image/jpeg or image/webp.
Does an image response have to use HTTP status 200?
A successful image response commonly uses 200. Conditional file handling may instead return 304 when a valid client copy is unchanged; error responses should report the failure rather than masquerade as image content.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

