How to view and delete images using the media plugin

3 replies
Last updated: Sep 14, 2020
Is there a way to see (and delete) all of your images? The only way I know how to see what images I have uploaded is when I go to choose one to assign as a cover image for my blog post
AI Update

I understand you're looking to view and manage all your uploaded images in Sanity! Yes, there are several ways to see and delete your images beyond just the image picker.

Using the Vision Tool to View All Images

The easiest built-in way is to use Vision, which comes preinstalled in Sanity Studio. You'll find it in your Studio's toolbar. Once there, you can run GROQ queries to see all your images:

*[_type == "sanity.imageAsset"]

This will show you all image assets in your dataset. From here, you can see details like upload dates, file sizes, and references. Vision now even supports saved queries, so you can save this for quick access later.

Using the Media Library (Enterprise Feature)

If you're on an Enterprise plan, Sanity offers Media Library - a centralized, organization-wide asset management system. This provides a dedicated interface where you can:

  • View all your images in a visual grid
  • Sort, filter, and search assets
  • Upload new assets via drag-and-drop
  • Manage asset metadata and versions with custom aspects
  • See which documents are using each asset
  • Delete unused assets

Media Library treats assets as structured content rather than just blob storage, giving you much more control over organization and management.

Deleting Images

To delete images, you have a few options:

  1. Via API/CLI: You can use the Sanity CLI or HTTP API to delete assets programmatically
  2. Via Vision: While Vision is primarily for querying, you can identify unused assets there and use mutations to delete them
  3. Via Media Library: If you have access, this provides the most user-friendly deletion interface

Keep in mind that deleting an asset that's still referenced in documents will break those references, so it's good practice to check usage first.

Alternative: Structure Tool Customization

You can also customize your Studio using the Structure Builder to create a dedicated view for browsing assets, though this requires some custom configuration.

The Vision tool is your quickest path to viewing all images right now, while Media Library (if available to you) provides the most complete asset management experience similar to what you might expect from other CMS platforms.

Looks like the media plugin does it
I don’t know if this applies to media but i know with documents you can run a sanity exec on a script which will groc all docs and delete them. If the plugin doesn’t do a delete all this might be a way to do that too
I was actually more looking for something to explore all of my media and delete individual ones if necessary. The media plugin does exactly what I was looking for

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?