Product Metafield with file type not returning url

50451
Tourist
4 0 2

I'm attempting to access a product metafield with a file content type. However I'm running into issues.

The metafield is set up as below.

50451_0-1626619238385.png

 

As far as I am aware the metafield with this setup should return a generic_file object that should allow access to id, media_type, preview_image, and url.

When trying to access on a product page using the liquid code  {{ product.metafields.my_fields.product_instructions.url }} I get nothing returned. 

However when using {{ product.metafields.my_fields.product_instructions }} on a product page where the product has a file metafeild set the follwing is returned gid://shopify/GenericFile/22363445657783

When no metafield is set as expected nothing is returned.

 

 

Anthony_David_
Trailblazer
221 29 86

Share product url

Shopify Expert - Theme customization | Design | Marketing | Product Sales
Hire Me: anthonyuidesigner@gmail.com
Whatsapp ( Click on number )- +33 6 28 93 62 05
0 Likes

Interesting question, I'd like to know more and check.

Which file type/format are you trying to reference in the metafields file object?

• If the problem is solved remember to click ✅ to Accept Solution
• Press Like ?? if the answer was helpful
• Shopify/Shopify Plus custom development, optimization and consulting. You can hire me here.
50451
Tourist
4 0 2

It's a pdf that's being referenced.

I was expecting to be returned a generic file object as per the metafield object docs. From which I could access id/media_type/preview_image/url as per  the generic_file object docs.

Interestingly it instead appears to return a type of Metafields::MetafieldDrop which I can't find any reference to anywhere. This can be seen if you try to use something like asset_url where you get the error "Liquid error (sections/test.liquid line 1): Expected input to be a String but got Metafields::MetafieldDrop"

 I've used the below code instead, utilising the file_reference metafield filter which works for my uses, but it is not what I had expected from the docs.

{{ product.metafields.my_fields.product_instructions | file_reference }}

 

It is indeed something strange and the documentation need to be improved. I submitted a report on that documentation page.

In the meanwhile the only way that I was able to get the file URL path was using this

File URL: {{ product.metafields.specs.pdf_file | file_url }}

 

• If the problem is solved remember to click ✅ to Accept Solution
• Press Like ?? if the answer was helpful
• Shopify/Shopify Plus custom development, optimization and consulting. You can hire me here.
0 Likes