Sanity Media Library - How to Add Images to a Slide Show
You've actually discovered one of the most powerful and flexible patterns for managing images in Sanity! Your "photo as a document" approach is not only valid but often the recommended best practice for structured media management with rich metadata. Let me explain why this works so well and when you might consider alternatives.
Why Your Document Pattern Works Great
Your approach of creating a photo document type with custom metadata fields and an image field is exactly what many experienced Sanity developers do. Here's why it's powerful:
1. Metadata Travels With Content By storing alt text, titles, and other metadata at the document level, you ensure this information is always accessible and can be updated in one place. When you reference this photo elsewhere, you're referencing the entire package of image + metadata.
2. Full GROQ Query Power You can search, filter, and query your photos using all of Sanity's GROQ capabilities. Want to find all photos by a specific artist from the Renaissance period? Easy with your schema.
3. Version Control Built-In When you upload a new image to an existing photo document, you're essentially versioning that asset while keeping all the metadata and references intact.
4. Reusability Using references (as you did with your carousel) means updating the photo in one place updates it everywhere it's used.
Understanding Sanity's Image Type
The native image type does support custom fields directly on the image field itself:
{
name: 'image',
type: 'image',
fields: [
{name: 'alt', type: 'string', title: 'Alt text'},
{name: 'caption', type: 'string', title: 'Caption'}
]
}However, this approach has limitations:
- Metadata is tied to that specific usage, not the asset itself
- You'd need to re-enter metadata each time you use the image
- Searching across all images becomes harder
When to Use Media Library (Enterprise)
Sanity does offer an Enterprise Media Library with advanced features like:
- Aspects: Schema-style custom metadata that lives on the asset itself
- Asset Versions: True version control with usage tracking
- Organization-wide asset management across projects
This is overkill for most projects and requires an Enterprise plan. Your document pattern gives you 90% of these benefits without the cost.
When to Use Media Plugins
Third-party plugins like sanity-plugin-media are useful when:
- You want a better browsing/upload UI than the default asset source
- You need basic tagging and search within the asset picker itself
- You're on a budget and need something between basic assets and Enterprise Media Library
However, these plugins typically store metadata on the asset document itself, which can be harder to query from your content documents compared to your reference pattern.
Best Practices for Your Approach
Your pattern is solid, but here are some refinements:
1. Add Asset Metadata Extraction You can still leverage Sanity's built-in image metadata like EXIF data, dimensions, and color palette:
{
name: "image",
type: "image",
options: {
hotspot: true,
metadata: ['exif', 'palette', 'location']
}
}2. Consider Validation Make alt text required for accessibility:
{
type: 'string',
name: 'alt',
title: 'Alt Text',
validation: Rule => Rule.required()
}3. Add Preview Configuration Make your photo documents easier to browse:
preview: {
select: {
title: 'title',
media: 'image'
}
}The Verdict
Your approach is not missing anything critical. You've independently discovered a pattern that scales well for structured content. The document-as-media-object pattern is particularly well-suited for:
- Art galleries and museums (like your artwork use case)
- Product photography with detailed specs
- Editorial images with rights management
- Any scenario where images have rich, queryable metadata
Stick with your pattern unless you need organization-wide asset management across multiple projects (Enterprise Media Library) or just want a prettier upload UI (community plugins). You're building on solid Sanity fundamentals, and your 10-minute solution is better than many over-engineered alternatives.
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.