
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeBased on your error and the fact that you can create documents but not upload assets, this is likely one of a few common issues with the assets.upload() method:
Most Common Causes:
v2023-05-17. Some older API versions have had issues with asset uploads. Try updating your Sanity client to use a more recent API version or omit it to use the default:const client = createClient({
projectId: 'your-project-id',
dataset: 'production',
token: 'your-token',
useCdn: false,
apiVersion: '2024-01-01' // or newer
})Token Permissions: Even though you have a token, make sure it has the correct permissions for asset uploads. Your token needs Editor or Administrator permissions. Developer tokens sometimes have restricted scopes. Check in your Sanity Manage under API settings → Tokens.
File Stream Issue: When using fs.createReadStream(), make sure:
Try this more robust version:
const fs = require('fs')
async function uploadImage(localImagePath) {
try {
const imageStream = fs.createReadStream(localImagePath)
const imageAsset = await client.assets.upload('image', imageStream, {
filename: 'your-filename.jpg' // optional but recommended
})
console.log('Upload successful:', imageAsset)
return imageAsset
} catch (error) {
console.error('Upload failed:', error.message)
console.error('Full error:', error)
}
}Network/Firewall Issue: Since document creation works but asset uploads don't, check if there's a firewall or proxy blocking requests to the /assets/ endpoint specifically. Asset uploads go to a different endpoint than document mutations.
Client Configuration: Make sure you're using useCdn: false when uploading assets. The CDN is read-only, so writes need to go directly to the API.
Quick Debugging Steps:
npm install @sanity/client@latestIf you're still stuck after trying these, share the full error message including any statusCode or additional details from the error object, and that will help narrow it down further!
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store