Can I upload images to a specific document via the API?

2 replies
Last updated: Sep 10, 2021
Hi everyone, from my research it appears that one cant upload an image file to a specific document via the API, one can only upload image assets to the CMS, and then link documents to them manually? am I correct?
Sep 10, 2021, 5:23 AM
If you’re defining documents through the API this is correct.Ie, you upload the image to the asset api, await the request and then put the
the api returns to you into a field of the form:
"nameOfImageField":  {
    "_type": "image",
    "alt": "alt-text of image",
    "asset": {
      "_ref": "imageId",
      "_type": "reference"
on the document and then upload your document.
If you’re uploading through the Studio this happens behind the scenes automatically when you choose “upload image” on an “image” field of a document.
Sep 10, 2021, 6:53 AM
yeah I am trying to do as much as I can through the API, thank you!
Sep 10, 2021, 6:58 AM – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in