
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI understand you're having trouble uploading images to Sanity through the REST API, both in your application and when testing with Postman. While you didn't mention the specific error you're encountering, let me walk you through the proper way to upload images to Sanity and address common issues.
Based on the Sanity Assets API documentation, here's how to properly upload an image:
Endpoint:
POST https://{projectId}.api.sanity.io/{apiVersion}/assets/images/{dataset}Required components:
{projectId} with your Sanity project ID{apiVersion} with the API version (e.g., v2024-06-24){dataset} with your dataset name (usually production)Content-Type header to match your image type (e.g., image/jpeg, image/png)Authorization: Bearer {token} headerOptional query parameters:
filename - Original filenametitle - Asset titledescription - Asset descriptionmeta - Array of metadata to extract (e.g., palette, lqip, blurhash)If you're getting a 413 error, your image file is likely exceeding Sanity's upload size limits. While Sanity's documentation doesn't explicitly state a hard limit in the Assets API page, this typically means:
Make sure you're using a valid token with write permissions:
Authorization: Bearer YOUR_TOKEN headerHere's how to set up your Postman request correctly:
Method: POST
URL: https://YOUR_PROJECT_ID.api.sanity.io/v2024-06-24/assets/images/YOUR_DATASET
Headers:
Authorization: Bearer YOUR_TOKEN Content-Type: image/jpeg
Body:
Query Parameters (optional):
filename: my-image.jpgtitle: My Image TitleMake sure your Content-Type header matches your actual image format:
image/jpeg for JPG/JPEG filesimage/png for PNG filesimage/webp for WebP filesimage/gif for GIF filesIf the HTTP API continues giving you trouble, consider using the official JavaScript client which handles uploads more reliably:
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
token: 'your-token',
apiVersion: '2024-06-24',
})
// Upload from a file input or blob
client.assets
.upload('image', fileData, {
filename: 'my-image.jpg',
title: 'My Image'
})
.then(document => {
console.log('Upload successful:', document)
})
.catch(error => {
console.error('Upload failed:', error)
})If you share the specific error message you're seeing, I can provide more targeted guidance!
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