How to upload image asset to Sanity from URL instead of binary data?
curl \
-X POST \
-H 'Content-Type: image/jpeg' \
--data-binary "<https://dl.airtable.com/.attachments/image.jpg>" \{statusCode: 400, error: "Bad Request", message: "Invalid image, could not read metadata", details: "Input buffer contains unsupported image format"}Sanity can upload an image directly from a public or preauthorized HTTPS URL. Send a JSON request to the Assets API’s /from-url endpoint; Sanity downloads the image and creates its asset document for you.
curl --fail-with-body --max-time 360 \
-X POST \
-H "Authorization: Bearer $SANITY_API_TOKEN" \
-H "Content-Type: application/json" \
--data '{"url":"https://example.com/image.jpg","filename":"image.jpg"}' \
"https://YOUR_PROJECT_ID.api.sanity.io/v2024-06-24/assets/images/YOUR_DATASET/from-url"Replace the project, dataset, and source URL with your values, and use a token with upload permission. The source URL must return the image bytes and be accessible without additional authentication headers. For an Airtable attachment, use a current attachment download URL.
The response contains the asset document. Use document._id as the _ref in your document’s image field:
{
"_type": "image",
"asset": {
"_type": "reference",
"_ref": "IMAGE_ASSET_ID_FROM_THE_RESPONSE"
}
}The original command fails because --data-binary "https://..." sends the URL as text to an endpoint expecting image bytes. Uploading those bytes yourself still works via Assets API, Media Library API, and Sanity CLI, but it is no longer necessary for a supported HTTPS source URL.
Note: URL uploads support sources up to 50 MiB and upload times up to 5 minutes. For files, use /assets/files/YOUR_DATASET/from-url instead. See the Assets API reference for details.
You can also ask an assistant connected to Sanity MCP to upload the URL to your project and dataset. Assets stored in Media Library use the separate Media Library API.
Show original thread13 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.