Files, like JPGs and PDFs, which exist alongside your data, are considered assets. The Sanity Studio provides a hassle-free UI for uploading assets, and an unsurprising API for dealing with all asset concerns such as storage, resizing and deletion.

Asset types

image and file. In the future, we might provide specific support for audio and video files, but currently all non-image files belong in the file category.


Though Sanity lets you import a wide range of image formats like TIFF and SVG our currently supported image formats for processed output are: JPEG, PNG and WebP.

GIF and SVG can pass through the image pipeline untouched, but if you want them scaled they will need to be output as one of the three formats above.

To upload assets, use the /assets/images/<dataset> endpoint. Once you have the image URL you can request resized versions of the original image by appending query parameters.

See the Presenting Images documentation for more details.


When you need to upload a non-image file (say a PDF or a zip file) use the /assets/files/<dataset> endpoint. The response is similar to the one you get from an image, but the type will be fileAsset.

Upload an Asset

In some cases, uploading assets using the UI is impractical. Say you want to upload a ton of images. If so, you'll want to use the assets API directly.

To upload an image, do a POST request to

with your file in the request body. E.g.:

curl \
  -X POST \
  -H 'Content-Type: image/jpeg' \
  --data-binary "@/Users/mike/images/bicycle.jpg" \
import sanityClient from '@sanity/client'
import {basename} from 'path'
import {createReadStream} from 'fs'

const client = sanityClient({
  projectId: 'myProjectId',
  dataset: 'myDatasetName',
  token: 'myToken'

const filePath = '/Users/mike/images/bicycle.jpg'
client.assets.upload('image', createReadStream(filePath), {
  filename: basename(filePath)
}).then(imageAsset => {
  console.log('got imageAsset', imageAsset)
  "_id": "image-abc123_0G0Pkg3JLakKCLrF1podAdE9-538x538-jpg",
  "_type": "sanity.imageAsset", // type is prefixed by sanity schema
  "assetId": "0G0Pkg3JLakKCLrF1podAdE9",
  "path": "images/myproject/mydataset/abc123_0G0Pkg3JLakKCLrF1podAdE9-538x538.jpg",
  "url": "",
  "originalFilename": "bicycle.jpg",
  "size": 2097152, // File size, in bytes
  "metadata": {
    "dimensions": {
      "height": 538,
      "width": 538,
      "aspectRatio": 1.0
    "location":{ // only present if the original image contained location metadata
      "lat": 59.9241370,
      "lon": 10.7583846,
      "alt": 21.0

Deleting Assets

Deleting an asset can be performed by deleting the associated asset document.

import sanityClient from '@sanity/client'
const config = {
  projectId: 'myProjectID',
  dataset: 'mydataset',
  token: 'myToken'
const client = sanityClient(config)
  .then(result => {
    console.log('deleted image asset', result)

It's important to note that while the file is deleted, the CDN might have your asset cached so it may not disappear immediately.

Previous: Asset PipelineNext: Image URLs