🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Issue with returning null value for blurhash in image schema resolved with help from Geoff.

3 replies
Last updated: Jun 16, 2023
Hey everyone! My image
blurhash
always returns a
null
value and I am not sure why.. Here is my groq query:
*[_type == "homePage"] | order(_updatedAt desc) [0] {
  sections[] {
    ...,
    _type == "contentImage" => {
      ...,
      image {
        ...,
        "height": asset->metadata.dimensions.height,
        "width": asset->metadata.dimensions.width,
        "dimensions": asset->metadata.dimensions,
        "blurhash": asset->metadata.blurHash,
        "lqip": asset->metadata.lqip
      }
    }
  }
}
In my Vision tool I keep getting a
null
value, but all other values work..
My
picture
schema is like this:
export default {
  title: 'Image',
  name: 'picture',
  type: 'image',
  icon: ImageSquare,
  options: {
    hotspot: true,
    metadata: ['lqip', 'blurhash']
  },
  fields: [
    {
      title: 'Alternative Text',
      name: 'alt',
      type: 'string',
      description: 'A short description of the image. Important for SEO and accessiblity.',
      validation: (Rule) => Rule.required()
    },
    {
      title: 'Display Size (Aspect Ratio)',
      name: 'customRatio',
      type: 'string',
      description: 'Select how the image is displayed. This affects the aspect ratio of the image within its container.',
      options: {
        list: aspectRatios
      },
      initialValue: 'aspect-0'
    }
  ],
  preview: {
    select: {
      alt: 'alt',
      filename: 'asset.originalFilename',
      dimensions: 'asset.metadata.dimensions',
      image: 'asset'
    },
    prepare({ alt, dimensions, filename, image }) {
      return {
        title: alt ?? filename,
        subtitle: dimensions ? `${dimensions.width}px × ${dimensions.height}px` : '…',
        media: image ?? ImageSquare
      }
    }
  }
}

Jun 16, 2023, 6:17 PM
Hi (Removed Name). Is
contentImage
in your
homePage
schema of the type
picture
? If it is, was
blurhash
specified in your
metadata
array at the time the image was uploaded?
Jun 16, 2023, 6:30 PM
Hi
user A
No lol.. sorry its a bit confusing, the
picture
is the name of the schema, but it is a type of
image
. Hmm no it wasn't specified in my image at the time of upload.. Let me give that a try
Jun 16, 2023, 6:32 PM
Oh wow its working now haha.. Seems I had to upload the images after I declared my
metadata: ['lqip', 'blurhash']
. Thanks for the help (Removed Name) you're the man
Jun 16, 2023, 6:38 PM

Sanity– build remarkable experiences at scale

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

Was this answer helpful?