Asset Source API
As part of the Form API, you can define custom asset sources for both file and image inputs.
The form API includes options for working with assets. The file and image properties will both let you add to or override the list of available asset sources for their respective form inputs, as well as enable or disable direct uploads.
Properties
assetSources
array | AssetSource[]
Accepts either a static array of asset source definitions or a callback function that returns the same. The callback is called with the current list of active asset sources as its first argument and a context object as the second.
directUploads
boolean
Whether or not to allow direct uploading of images/files. Defaults to true.
Example
import {defineConfig} from 'sanity'
import {unsplashAssetSource} from 'sanity-plugin-asset-source-unsplash'
import {customSource} from './src/custom-asset-source'
export default defineConfig({
// ...rest of config
form: {
image: {
assetSources: (prev) => [...prev, unsplashAssetSource],
},
file: {
assetSources: [customSource],
directUploads: false,
},
},
})Context properties
These are the properties provided in the context object when defining asset sources using the callback function.
dataset
string
Name of the current dataset.
projectId
string
Unique ID for the project.
schema
object | Schema
The schema registry of your project. Use
schema.get("schemaTypeName")to retrieve any schema by name.currentUser
object | CurrentUser
An object with info about the currently logged-in user.
getClient
function | SanityClient
Asset source properties
Refer to the AssetSource type reference for a complete list of properties.
Asset source selection component props
Refer to the AssetSourceComponentProps type reference for a complete list of properties.