The Sanity engineering blog is live. Deep dives from our engineers.

How to grab image metadata from images inserted into Content blocks?

7 repliesLast updated: Nov 30, 2025

I’d really like to be able to grab image metadata from images inserted into Content blocks, but all I seem to be able to get back is a reference. How can I expand references contained inside portable text blocks?
AI Update

You can expand references inside Portable Text blocks, including image assets, by using GROQ's reference access operator (->) to dereference them in your query.

When you have images in your Portable Text content blocks, they're stored as references to asset documents. To get the full image metadata (dimensions, palette, LQIP, etc.), you need to expand those references when querying.

Here's how to do it:

*[_type == "article"]{
  body[]{
    ...,
    _type == "image" => {
      ...,
      asset->
    }
  }
}

This query:

If you only need specific metadata fields, you can project them:

*[_type == "article"]{
  body[]{
    ...,
    _type == "image" => {
      ...,
      asset->{
        _id,
        url,
        metadata {
          dimensions,
          palette,
          lqip
        }
      }
    }
  }
}

This also works for references in markDefs (like link annotations). For example, if you have reference annotations in your Portable Text:

*[_type == "article"]{
  body[]{
    ...,
    markDefs[]{
      ...,
      _type == "internalLink" => {
        ...,
        reference->
      }
    }
  }
}

The reference access operator documentation has more details on joining asset documents in Portable Text queries. The key is using the -> operator after any reference field to fetch the complete referenced document instead of just getting back the _ref ID.

Show original thread
7 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions