How to show image filename instead of "Untitled" in Sanity gallery array?

14 replies
Last updated: Nov 29, 2025
I have an gallery field which is an array of images, it works fine though the title preview of each image shows "Untitled", which doesn't look great. Ideally I'd like to show the filename of the image but I don't know how to get this working. There doesn't seem to be a way to do this in the docs .
AI Update

Good news—you can definitely show the filename! The key is placing the preview configuration on the image object itself, not on the array field.

When you add custom fields to an image type in an array, Sanity stops showing the default filename preview. You need to explicitly tell it what to display by adding a preview configuration. Here's how:

{
  name: 'gallery',
  type: 'array',
  of: [
    {
      type: 'image',
      fields: [
        {
          name: 'alt',
          type: 'string',
          title: 'Alt Text'
        }
      ],
      preview: {
        select: {
          title: 'asset.originalFilename',
          media: 'asset'
        }
      }
    }
  ]
}

The important bits:

  • title: 'asset.originalFilename' - This pulls the original filename from the image asset
  • media: 'asset' - This keeps the image thumbnail visible in the list

The asset object is automatically populated when you upload an image and includes read-only properties like originalFilename, url, size, etc. You don't need to create any additional fields—just reference asset.originalFilename in your preview select.

If you want to get fancier, you can use a prepare function to customize the display even further, but for showing filenames, the simple select approach above should work perfectly.

Show original thread
14 replies

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?