> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://contentful.com/developers/docs/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://contentful.com/_mcp/server. # Retrieve an image GET https://images.ctfassets.net/{space_id}/{asset_id}/{unique_id}/{name} Reference: https://contentful.com/developers/docs/references/images-api/images/retrieve-an-image ## Request ### Path parameters - `space_id` (string, required) — Alphanumeric id of the space to retrieve. - `asset_id` (string, required) — Alphanumeric id of the asset to which the image belongs. - `unique_id` (string, required) — Alphanumeric unique id identifying the image. - `name` (string, required) — The original file name of the image. ### Query parameters - `w` (double, optional) — The desired width of the image in pixels (cannot be zero). - `h` (double, optional) — The desired height of the image in pixels (cannot be zero). - `fm` (enum, optional) — The desired image output format. The default is the original image format. - Allowed values: `jpg`, `png`, `webp`, `gif`, `avif`, `tiff` - `fl` (enum, optional) — For JPEG images, you can request a progressive JPEG. Should be used in conjunction with the fm parameter set to jpg. For PNG images, you can request a 8-bit PNG. Should be used in conjunction with the fm parameter set to png. - Allowed values: `progressive`, `png8` - `fit` (enum, optional) — By default, images are resized to fit into the specified dimensions, only if the original asset is larger than the specified limit (width and height). The image will take up the maximum space within the bounding box that was provided, at its original aspect ratio. You can request a different behavior using the fit parameter. - Allowed values: `pad`, `fill`, `scale`, `crop`, `thumb` - `f` (enum, optional) — You can choose the focus area for resizing when using fit type pad, fill, crop or thumb. Focus area has no effect on the default or scale fit type. The default is center. - Allowed values: `center`, `top`, `right`, `left`, `bottom`, `top_right`, `top_left`, `bottom_right`, `bottom_left`, `face`, `faces` - `r` (string, optional) — You can add rounded corners to your image or crop to a circle/ellipse. The default is 0. Possible values: - The size of the corner radius in pixels (e.g., "20") - "max" keyword for a full circle/ellipse - `q` (double, optional) — Quality as a percentage, between 1 and 100. - `color` (string, optional) — A color constant. ## Response ### 200 OK - Request successful ## Examples **Response** ```json {} ``` **SDK Code** ```android Android // Create the Contentful client. final CDAClient client = CDAClient .builder() .setToken("") .setSpace("") .setEnvironment("") .build(); // Start an asynchronous stream from rx java, allowing execution on different threads. client // Get our asset. .observe(CDAAsset.class) .where("sys.id", "") .all() // Download url asset points to. .map(new Function() { @Override public byte[] apply(CDAArray array) { final CDAAsset asset = (CDAAsset) array.items().get(0); // Retrieve the url to be used. final String url = asset.urlForImageWith( https() ); // Create the network call, using the new url. final Call call = httpClient .newCall( new Request .Builder() .url(url) .build() ); // Try and retrieve the image. Response execute; try { execute = call.execute(); } catch (IOException e) { // Networking layer failed. throw new IllegalStateException("Downloading the url threw an error.", e); } // Fetch the body. try { return execute.body().bytes(); } catch (IOException e) { // The body could not be fetched. throw new IllegalStateException("Could not read body.", e); } } }) // Execute result handling on the `main thread`. .observeOn(AndroidSchedulers.mainThread()) // Networking should happen on io thread. .subscribeOn(io.reactivex.schedulers.Schedulers.io()) .subscribe( new DisposableSubscriber() { byte[] result; @Override public void onComplete() { // Retrieval of Image complete, now display it in an alert. final View view = LayoutInflater.from(context).inflate(layoutId, null, false); final ImageView image = (ImageView) view.findViewById(imageId); final Bitmap bitmap = BitmapFactory.decodeByteArray(result, 0, result.length); image.setImageBitmap(bitmap); new AlertDialog.Builder(context) .setTitle("Contentful Image") .setView(view) .show(); } @Override public void onError(Throwable error) { Log.d("CONTENTFUL", "Could not request asset.", error); } @Override public void onNext(byte[] data) { result = data; } } ); ``` ```java Java // Create the Contentful client. final CDAClient client = CDAClient .builder() .setToken("") // required .setSpace("") // required .setEnvironment("") // optional, defaults to `master` .build(); // Create an okhttp client for networking. final OkHttpClient httpClient = new OkHttpClient .Builder() .build(); // Retrieve one asset to be used. final CDAAsset asset = client .fetch(CDAAsset.class) .one(""); // Save it's url. final String url = asset.url(); // Add the protocol to url. final String url = asset.urlForImageWith(https()); final Call call = httpClient .newCall( new Request .Builder() .url(url) .build() ); // Request the image. final Response response = call.execute(); // Read image in `png` format. final byte[] bytes = response.body().bytes(); ``` ```kotlin Kotlin // Create the Contentful client. val client = CDAClient .builder() .setToken("") // required .setSpace("") // required .setEnvironment("") // optional, defaults to `master` .build() // Create an okhttp client for networking. val httpClient = OkHttpClient.Builder() .build() // Retrieve one asset to be used. val asset = client!! .fetch(CDAAsset::class.java) .one("") // Add the protocol to url. val url = asset.urlForImageWith(https()) val call = httpClient .newCall( Request.Builder() .url(url) .build() ) // Request the image. val response = call.execute() // Read image in `png` format. val bytes = response.body()!!.bytes() ``` ```swift Swift import Contentful // Retain the client as a property on a type you define so that // the client's asynchronous network callbacks are executed. let client = Client(spaceId: "", environmentId: "", // Defaults to "master" if omitted accessToken: "") // Snippets for the images API assume that you already have an `Asset` in memory. var asset: Asset = ... // Type passed into callback will be a UIImage or NSImage depending on the current platform. client.fetchImage(for: asset) { (image: Result) in switch result { case .success(let image): // Use the image. case .error(let error): print(error) } } ``` ```javascript JavaScript // contentful.js v4.x.x import { createClient } from 'contentful-management' const client = createClient({ space: '', accessToken: '' }) const asset = client.getAsset('') .then((asset) => console.log(asset.fields.file.url)) ``` ```php PHP $client = new Contentful\Delivery\Client('', ''); $asset = $client->getAsset(''); $resultUrl = $asset->getFile()->getUrl(); ``` ```ruby Ruby require 'contentful' client = Contentful::Client.new( space: '', access_token: '', environment: 'master', # Optional - defaults to 'master'. dynamic_entries: :auto # Enables Content Type caching. ) asset = client.asset('') ``` ```python Python from contentful import Client client = Client( '', '', environment='master' # Optional - it defaults to 'master'. ) asset = client.asset('') asset.url() ``` ```.net .NET // This client should only be created once per application. var httpClient = new HttpClient(); var client = new ContentfulClient(httpClient, "", "", ""); // Retrieve an asset that represents your image. var asset = client.GetAsset(""); // This is the base URL for the image. var imageUrl = asset.File.Url; ```