Class AssetsClient

Client for managing assets (files and images) in Sanity. Provides methods for uploading, deleting and managing assets.

// Upload an image from Node.js
const imageAsset = await client.assets.upload('image', fs.createReadStream('image.jpg'), {
filename: 'image.jpg'
})

// Upload a file from the browser
const fileAsset = await client.assets.upload('file', new File(['foo'], 'file.txt'), {
filename: 'file.txt'
})

// Delete an asset
await client.delete('image-abc123_foobar-123x123-png')

Constructors

Methods

Constructors

Methods

  • Delete an asset by ID. This will also delete the actual asset file/image.

    Parameters

    • id: string

      Asset document ID to delete

    Returns Promise<void>

    Promise resolving when asset is deleted