Media Library

Configure your studios and CLI to use Media Library

Once Media Library is enabled for your organization, you can connect it to your Studio and the CLI.

This articles covers enabling Media Library in your Studio, managing asset sources, and configuring the sanity CLI to create and deploy aspects.

This is a paid feature

This feature is available as an addon for certain Enterprise plans. Talk to sales to learn more.

Prerequisites:

  • npm, pnpm, or a similar package manager capable of installing and running the sanity CLI.
  • Read/write access to your organization's Media Library.
  • Studio v3.82.0 or later for Studio integration. Learn how to upgrade your Studios.

Obtain your mediaLibraryId

When you interact with the sanity media commands, you're prompted to select your library. If you only have a single organization, you should see a single library. If you're a member of multiple organizations, you can parse your organization and library ID using the URL.

Navigate to sanity.io/welcome, select your organization, then select the Media Library app. The URL for your library includes the mediaLibraryId.

https://www.sanity.io/@<organizationId>/media/<mediaLibraryId>/assets

Configure Studio

Media Library integration with Studio lets editors select assets from the library for use in their documents, and upload new files and images to the library.

Loading...

Enable Media Library support by setting mediaLibrary.enabled to true in your sanity.config.ts file.

Token-based authentication should also be enabled by setting auth.loginMethod to 'token' to ensure full functionality.

The optional libraryId setting connects the Studio to a specific library. If you don't provide it, the Media Library is detected automatically. Set it to the mediaLibraryId you obtained earlier if your studio does not detect the library.

Authentication

Some Media Library features are unsupported when using cookie-based authentication. To ensure full functionality, we strongly recommend using token-based authentication.

Currently unsupported features:

  • Previewing private assets, both in Studio and when selecting assets from the Media Library
  • Managing signing keys
  • Downloading assets
  • Syncing asset version usage

Optional: disable the default source

If you want to move completely to Media Library, you can disable the default media source. Use the form.image.assetSources configuration in your Studio config file (sanity.config.ts) to filter the sources.

This example keeps Media Library and any custom sources, but removes the default media select option.

If you'd like to be more explicit and target the Media Library source, you can do so by comparing the source name with sanity-media-library.

Add filters to image type selector

You can add selectable filters to the Studio image type by adding the mediaLibrary option to the image type's options object.

Each filter has a name and query. The query is a GROQ query filter that runs against the Media Library dataset. If it returns true, the matching image is displayed.

Configure the CLI

Tell sanity CLI where to define your aspects by updating sanity.cli.ts.

With the aspects path defined, you can now use the media commands to create and deploy aspects.

Was this page helpful?