Can custom asset sources' `assetDocumentProps` be exposed as editable fields under an image?

2 replies
Last updated: Nov 16, 2023
With custom asset sources, you have the option to set
assetDocumentProps
like
description
and
creditLine
. Can these be exposed as editable fields under an image? I was hoping if I match the props to the props under
fields
on my image type field but that doesn't seem to work.
AI Update

Based on the documentation about custom asset sources in Sanity, the assetDocumentProps you set when selecting assets (like description and creditLine) are properties that get saved directly on the asset document itself, not on the image field in your document.

This is an important distinction: when you use an image field in your schema, you're creating a reference to an asset document, and any custom fields you define on that image field are stored on your document, not on the asset.

The Short Answer

No, simply matching the field names won't automatically expose assetDocumentProps as editable fields. The description and creditLine from assetDocumentProps are saved on the asset document, while custom fields you define on your image field are saved on your document's image field value.

What You Can Do

You have a few options:

1. Add Custom Fields to Your Image Field

You can add custom fields to your image schema type that will be editable in the Studio:

{
  name: 'mainImage',
  title: 'Main Image',
  type: 'image',
  fields: [
    {
      name: 'description',
      type: 'string',
      title: 'Description'
    },
    {
      name: 'creditLine',
      type: 'string',
      title: 'Credit Line'
    }
  ]
}

These fields will be editable in your Studio, but they're separate from the asset's description and creditLine properties.

2. Create a Custom Input Component

If you want to display and edit the asset document's metadata (including description and creditLine) directly from your document editor, you'll need to create a custom input component. This is more advanced but gives you full control.

There's actually a guide specifically for this use case: Awesome custom input component for metadata that shows how to create a custom input that allows editing asset metadata at the document level.

3. Use the Media Library Plugin

If you're using the Media Library (Enterprise feature), you can manage asset metadata centrally, though you'd still need a custom input to edit it from within individual documents.

The Key Distinction

  • Asset document properties (assetDocumentProps): Stored on the sanity.imageAsset document
  • Image field custom fields: Stored on your document's image field value

Both can have fields named description and creditLine, but they're stored in different places and serve different purposes. Asset properties are shared across all uses of that asset, while image field properties are specific to each document.

You could, but you would need to create a custom component that edited the image document’s metadata. You won’t be able to use the built in field functionality.
Ok makes sense, thanks!

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.

Was this answer helpful?