capabilities.work

Upload Asset and Reference

A 2-step recipe with Sanity. We can help you get access.

Recipe · 2 steps

Upload Asset and Reference

with Sanity

Upload an image asset and wire it into a new document via a reference.

  1. Upload the binary image to the Content Lake and capture the asset document id and public url.
  2. Create a document with an image field whose asset reference points at the uploaded asset id.
What you'll need to have ready
  • projectId: The Sanity project id that scopes the API endpoint.
  • apiToken: Sanity project API token used as a Bearer credential.
  • dataset: Dataset name to upload into and write into.
  • imageBinary: Raw binary image content to upload (JPEG, PNG, WebP, GIF, or SVG).
  • filename: Optional original filename to record on the asset.
  • documentId: The _id to assign to the new referencing document.
  • documentType: The _type of the new document that will hold the image.
For your developer

Arazzo workflow sanity:upload-asset-and-reference, 2 operations: uploadImageAsset → mutateDocuments. Specs on APIs.io.