Importing images to Sanity - possible workaround using ndjson
You're actually not quite right about that! While the documentation you're reading focuses on importing images within documents, you can absolutely upload images to Sanity directly without attaching them to a document first. The images will then be available in your asset library for authors to use later.
Uploading images without documents
You can upload standalone images using the Assets API. When you upload an image, Sanity automatically creates a sanity.imageAsset document that stores the metadata, but you don't need to create or reference it from any other document. These assets live independently in your dataset and are available for authors to browse and use.
Using the JavaScript client
import {createClient} from '@sanity/client'
const client = createClient({
projectId: 'myProjectId',
dataset: 'myDatasetName',
apiVersion: '2021-08-29',
token: 'myToken'
})
// Upload the image - it's now available in your asset library
client.assets
.upload('image', createReadStream('/path/to/image.jpg'), {
filename: 'bicycle.jpg'
})
.then(imageAsset => {
console.log('Uploaded!', imageAsset._id)
// The image is now in your library, ready for authors to use
})Using the HTTP API directly
You can also POST directly to the Assets API endpoint:
curl -X POST \
-H 'Content-Type: image/jpeg' \
--data-binary "@/path/to/image.jpg" \
'https://myProjectId.api.sanity.io/v2021-06-07/assets/images/myDataset'Both methods create the asset document automatically, making the image available in Studio's asset picker.
Browsing uploaded assets
Authors can access these pre-uploaded images through:
- The built-in image picker in any image field
- The Sanity Media plugin which provides a dedicated asset browser
- The Media Library (Enterprise feature) for organization-wide asset management with tagging and metadata
Querying standalone assets
You can also query all uploaded images using GROQ:
*[_type == "sanity.imageAsset"]So to directly answer your question: No, images don't need to be part of a document to be imported. You can upload them standalone, and they'll be immediately available for your authors to use wherever they need them in their content.
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.