Media CLI command reference

CLI reference documentation for the media command.

Interact with Media Library with the npx sanity media command.

npx sanity media --help

Run create-aspect and deploy-aspect from a directory whose sanity.cli.ts sets mediaLibrary.aspectsPath. The other commands also work outside a project when you pass --project-id. Learn more about configuring Media Library.

Commands

create-aspect

USAGE
  $ sanity media create-aspect [--name <value>] [--title <value>]

FLAGS
      --name=<value>   Aspect name. Defaults to the title in camel case
      --title=<value>  Aspect title

DESCRIPTION
  Create a new aspect definition file

EXAMPLES
  Create a new aspect definition file

    $ sanity media create-aspect

delete-aspect

USAGE
  $ sanity media delete-aspect ASPECTNAME [-p <id>] [--yes] [--media-library-id <value>]

ARGUMENTS
  ASPECTNAME  Name of the aspect to delete

FLAGS
  -y, --yes                       Run without prompts and confirm deletion
      --media-library-id=<value>  The id of the target media library

OVERRIDE FLAGS
  -p, --project-id=<id>  Project ID to delete media aspect from (overrides CLI configuration)

DESCRIPTION
  Delete an aspect definition

EXAMPLES
  Delete the aspect named "someAspect"

    $ sanity media delete-aspect someAspect

deploy-aspect

USAGE
  $ sanity media deploy-aspect [ASPECTNAME] [-p <id>] [--all] [--media-library-id <value>]

ARGUMENTS
  [ASPECTNAME]  Name of the aspect to deploy

FLAGS
      --all                       Deploy all aspects
      --media-library-id=<value>  The id of the target media library

OVERRIDE FLAGS
  -p, --project-id=<id>  Project ID to deploy media aspect to (overrides CLI configuration)

DESCRIPTION
  Deploy an aspect

EXAMPLES
  Deploy the aspect named "someAspect"

    $ sanity media deploy-aspect someAspect

  Deploy all aspects

    $ sanity media deploy-aspect --all

export

USAGE
  $ sanity media export [DESTINATION] [-p <id>] [--asset-concurrency <value>] [--media-library-id <value>] [--no-compress] [--overwrite]

ARGUMENTS
  [DESTINATION]  Output destination file path

FLAGS
      --asset-concurrency=<value>  Concurrent number of asset downloads
      --media-library-id=<value>   The id of the target media library
      --no-compress                Skips compressing tarball entries (still generates a gzip file)
      --overwrite                  Overwrite any file with the same name

OVERRIDE FLAGS
  -p, --project-id=<id>  Project ID to export media from (overrides CLI configuration)

DESCRIPTION
  Export file and image assets from a media library (excludes video)

EXAMPLES
  Export media library interactively

    $ sanity media export

  Export media library to output.tar.gz

    $ sanity media export output.tar.gz

  Export specific media library

    $ sanity media export --media-library-id my-library-id

import

USAGE
  $ sanity media import SOURCE [-p <id>] [--aspect <key=value>] [--filename <filename>] [--media-library-id <value>] [--replace-aspects]

ARGUMENTS
  SOURCE  Directory, archive, or asset URL to import from. An https URL imports one asset that Sanity fetches itself

FLAGS
      --aspect=<key=value>        Aspect value to set on the imported asset, as key=value. Repeatable. Only applies when the source is a URL - directory and archive imports read aspects from their data.ndjson
      --filename=<filename>       Original filename to store on the asset. Only applies when the source is a URL. Defaults to a name derived from the URL
      --media-library-id=<value>  The id of the target media library
      --replace-aspects           Replace existing aspect data. All versions will be replaced (e.g. published and draft aspect data). Only applies to directory and archive imports

OVERRIDE FLAGS
  -p, --project-id=<id>  Project ID to import media to (overrides CLI configuration)

DESCRIPTION
  Import a set of assets to the target media library.

EXAMPLES
  Import all assets from the "products" directory

    $ sanity media import products

  Import all assets from "gallery" archive

    $ sanity media import gallery.tar.gz

  Import all assets from the "products" directory and replace aspects

    $ sanity media import products --replace-aspects

  Have Sanity fetch a single asset from a public URL

    $ sanity media import https://example.com/hero.png

  Fetch an asset from a URL and set aspect data on it

    $ sanity media import https://example.com/hero.png --aspect department=Brand

Was this page helpful?

sanity.ioAll Systems Operational© Sanity 2026
Change site theme