How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

Sanity image upload error: Request failed to assets/images API endpoint

2 repliesLast updated: Nov 29, 2025

Hey Everyone! When I try to upload a file through this code:

await _sanityClient_.assets.upload('image', fs.createReadStream(localImagePath)).then((_data_) _=>_ {

console.log(_data_)

})

.catch((_error_) _=>_ {

console.log("Upload failed: ", _error_)

});

It gives me an error : Request error while attempting to reach
https://projectID.api.sanity.io/v2023-05-17/assets/images/production
Any help on this?

I'm using a token for developer so I have to be able to connect to the api and only happens when trying to upload an image not creating documents.
AI Update

Based 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:

const client = createClient({
  projectId: 'your-project-id',
  dataset: 'production',
  token: 'your-token',
  useCdn: false,
  apiVersion: '2024-01-01' // or newer
})

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)
  }
}

Quick Debugging Steps:

If 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!

Show original thread
2 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

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.

Related contributions