Media Library
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
pnpm dlx sanity media --help
yarn dlx sanity media --help
bunx sanity media --help
The media command must be run from within a directory that contains a valid santy.cli.ts configuration file. We recommend running it from within an existing Sanity project. Learn more about configuring Media Library.
Commands
create-aspect
USAGE
$ sanity media create-aspect
DESCRIPTION
Create a new aspect definition file
EXAMPLES
Create a new aspect definition file
sanity media create-aspectdelete-aspect
USAGE
$ sanity media delete-aspect ASPECTNAME
ARGUMENTS
ASPECTNAME Name of the aspect to delete
FLAGS
--media-library-id=<MEDIA-LIBRARY-ID>The id of the target media library
--yes Skip confirmation prompt
DESCRIPTION
Undeploy an aspect
EXAMPLES
Delete the aspect named "someAspect"
sanity media delete-aspect someAspectdeploy-aspect
USAGE
$ sanity media deploy-aspect [ASPECTNAME]
ARGUMENTS
[ASPECTNAME] Name of the aspect to deploy
FLAGS
--all Deploy all aspects
--media-library-id=<MEDIA-LIBRARY-ID>The id of the target media library
DESCRIPTION
Deploy an aspect
EXAMPLES
Deploy the aspect named "someAspect"
sanity media deploy-aspect someAspect
Deploy all aspects
sanity media deploy-aspect --allexport
USAGE
$ sanity media export [DESTINATION]
ARGUMENTS
[DESTINATION] Output destination file path
FLAGS
--asset-concurrency=<ASSET-CONCURRENCY>Concurrent number of asset downloads
--media-library-id=<MEDIA-LIBRARY-ID>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
DESCRIPTION
Export an archive of all file and image assets including their aspect data from the target media library. Video assets are excluded from the export.
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-idimport
USAGE
$ sanity media import SOURCE
ARGUMENTS
SOURCE Image file or folder to import from
FLAGS
--media-library-id=<MEDIA-LIBRARY-ID>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)
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