Help articles

Invalid asset metadata field

Schema validation reports Invalid type for image `metadata` field - must be an array of strings or Invalid type for file `metadata` field - must be an array of strings when the metadata option isn't an array of strings.

The metadata option on an image field lists which metadata Sanity extracts from an uploaded file and writes to the asset's metadata document. Its value must be an array of strings:

Valid values are blurhash, thumbhash, lqip, palette, exif, image, and location.

dimensions, hasAlpha, and isOpaque are always included and can't be listed. Adding them produces a separate warning: Image `metadata` field contains superfluous properties (they are always included): followed by the names.

The same validation runs for file fields, but metadata is missing from the FileOptions type, so TypeScript rejects it on a file field even though the Studio accepts it.

This example extracts palette and location data for any image uploaded to the field and stores it on the asset. You can then query it:

*[_type == "article"][0...10]{
  ...,
  "coverPhoto": coverPhoto.asset->{
    url,
    metadata {
      location,
      palette {
        dominant {
          background,
          foreground
        }
      }
    }
  }
}

The result looks like this:

[
  {
    "_id": "some-blog-post",
    "_type": "article",
    "title": "Some blog post",
    "coverPhoto": {
      "url": "https://cdn.sanity.io/images/YOUR_PROJECT_ID/production/aa1N73Zv14r7pYsbUdXl-4288x2848.jpg",
      "metadata": {
        "location": {
          "_type": "geopoint",
          "alt": 12.4,
          "lat": 59.924104,
          "lng": 10.758437
        },
        "palette": {
          "dominant": {
            "background": "#99b8cd",
            "foreground": "#000"
          }
        }
      }
    }
  }
]

For every metadata value and what it returns, see Image metadata.

Was this page helpful?