Metafield Image - Get URL not GID externally

Hello,

I have an image metafield on products that outputs a GID when accessed externally via API, but I need it to be a URL.

Is there an easy way to do this (we have a lot of products so hopefully this would not be a product-by-product fix).

Thanks!

Thanks for your response. Is there documented way to do this for our many products?

We are happy to utilise Flow or Mechanic or another solution, but I’d love to hear if anyone can point me in the right direction.

@no_robotocha @Sophiaatouch2

GID (Google Drive File ID)

A shopify GID is a Global Identifier , it is not about google-drive.

@no_robotocha See this?

https://community.shopify.com/c/graphql-basics-and/how-to-get-media-src-by-using-metafield-file-type-in-graphql-or/td-p/1326275

Generally CDN url was normally only generated for the frontend channels, so if the above does not work then to get those CDN urls basically need to either setup a special page using liquid on the frontend to spit out the GID & URL values (remembering things like pagination), or scrape the frontend. There’s an example in the mechanic slack channel but it’s about incoming_inventory not image urls.

Spitball , there’s also just testing if there’s an undocumented { url } as if you were working with a product image https://community.shopify.com/c/hydrogen-headless-and-storefront/graphql-product-image-url/td-p/1431636

Also post to the https://community.shopify.com/c/metafields-and-custom-data forum. And if nothing comes up after careful testing submit a feature request to shopify partner support either for this feature or better documentation.

Tangentially related:

https://community.shopify.com/c/graphql-basics-and/product-image-upload-using-graphql-without-url/m-p/53376

1 Like

Hi @PaulNewton

Thank you so much for this in-depth feedback - very helpful and I’m a lot more confident of a solution. I’ll let you know how it goes.

Hi @no_robotocha did you find a solution to this?

I found a couple, depending on the situation - what’s your situation and I’ll see if I can help?

Thanks for replying so quickly!

The initial images load correctly within my liquid:

{{ image | image_url: width: 200, height: 200 | image_tag: alt: ā€œGallery Imageā€, class: ā€˜gallery-img’, srcset: nil }}

Now, I’m trying to swap images with an onclick event. I can retrieve the ā€œgid://shopify/MediaImage/36560205775154ā€, but then when I swap in javascript using the galleryImage.src= gid://shopify/MediaImage/36560205775154, my image cannot be found.

Okay I’m not exactly sure in your case, but the answer is probably how you’re requesting the image if you’re making an API request (as per this) or if using liquid something like

{{ tile.metafields.custom.product_alt_image | image_url: width: 360 }}

Then if neither of those are helpful, perhaps use javascript to replace ā€œgid://shopify/MediaImage/ā€ with the CDN URL that you find when you go to Content > Files and copy an image link as this seems to be the same URL for all your images.

Hope this helps!

2 Likes