Can someone point me to the docs where you return a URL for an image?
25 replies
Last updated: Jul 21, 2020
E
Can someone point me to the docs where you return a url for an image?I keep seeing the url param returned in sample objects - but not seeing it on my end - what am I missing?
For my images: I have an
For my images: I have an
assetproperty - which is where I would assume the
urlwould be. However I am only getting a
_refand a
type.
Jul 20, 2020, 8:56 PM
B
where are you trying to return the URL?
in sanity? gatsby? something else?
in sanity? gatsby? something else?
Jul 20, 2020, 9:06 PM
E
user N
Thanks for asking for more context.Returning the URL in a nextjs frontend using sanity groq query.
Jul 20, 2020, 9:08 PM
B
mmm, ok, i've not used nextjs but let me see if i can't still help you out
Jul 20, 2020, 9:08 PM
E
Sweet thanks. I saw there are a few examples of image packages used for gatsby and such - but thats a little overkill for what I am looking for.
Specifically referencing this:
https://www.sanity.io/docs/image-type#example-of-a-image-asset-object-with-metadata-location-lqip-palette-and-dimensions-df3f768ce073
Returns a
Specifically referencing this:
https://www.sanity.io/docs/image-type#example-of-a-image-asset-object-with-metadata-location-lqip-palette-and-dimensions-df3f768ce073
Returns a
urlbut no reference on how to do so or where it comes from.
Jul 20, 2020, 9:10 PM
E
Ooh i think im seeing where - you drop the
metadatainto your
optionscall and specify what you want to return. Iโll try this.
Jul 20, 2020, 9:11 PM
E
Hmm - not that. Url seems to live outside of metadata somewhere!
Jul 20, 2020, 9:12 PM
B
you've seen this?
Jul 20, 2020, 9:13 PM
B
Jul 20, 2020, 9:13 PM
B
you might need to use the
@sanity/image-urlplugin
Jul 20, 2020, 9:14 PM
B
not 100% sure about that
Jul 20, 2020, 9:14 PM
E
Yea that was step 2. ๐
Jul 20, 2020, 9:14 PM
E
Iโll dig in a bit more after dinner - thanks for the help so far!
Jul 20, 2020, 9:15 PM
E
image.asset->url- asset does not return url as a data point: only getting
_refand
typeback ๐คทโโ๏ธ
Jul 20, 2020, 9:15 PM
B
*[_type == 'person']{ name, "imageUrl": image.asset->url }
Jul 20, 2020, 9:15 PM
B
haha, ok, you saw that
Jul 20, 2020, 9:15 PM
E
Yup ๐ im just racking my brains on why its missing - it seems like a standard return based on the docs
Jul 20, 2020, 9:16 PM
B
i think it would be something like
your-field-name.asset->url
Jul 20, 2020, 9:16 PM
E
In the interm i could build up the string using interpolation and the
_refitem ๐
Jul 20, 2020, 9:20 PM
B
have you tried
mainImage.asset->url?
Jul 20, 2020, 9:22 PM
B
is
mainImagea field or an object?
Jul 20, 2020, 9:23 PM
E
Yea I tried that - errors out.
Jul 20, 2020, 9:25 PM
E
user N
I think it was a syntax issue from the docs.Ended up running
mainImage.asset->{url}and got what I needed.
Jul 21, 2020, 3:42 AM
E
Also had to re read the groq docs concerning references ๐ - huge fan of all the sweet operators you can throw in there to return data.
Jul 21, 2020, 1:57 PM
B
oh nice, glad its working ... did you drop a note in the feedback channel so the sanity team can update the docs?
Jul 21, 2020, 2:42 PM
E
I did not - will do that now.
Jul 21, 2020, 3:46 PM
Sanityโ build remarkable experiences at scale
The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.