Diego Massarini
Diego Massarini

Reputation: 354

How to add and display multiple images with sanity.io?

I've tried to add more images in my sanity project without any result. I've add a schema for that.

{
  name: 'gallery',
  title: 'Gallery',
  type: 'array',
  of: [{ type: 'image', 
  options: {
    hotspot: true,
  },}]
 }

But when I console.log the result of the post where I upload more images I get only _ref and _type and no URL like in the mainImage.

How can I display multiple images? Thanks

Upvotes: 0

Views: 1748

Answers (1)

ran ia
ran ia

Reputation: 106

to get the url you need to fetch data like that :

client.fetch(`*[_type == 'post']{
    _id,
    title,
    gallery[]{
        asset->{
            url
        }
    }]
}`)......

Upvotes: 2

Related Questions