Product Metafield with file type not returning url

50451
Tourist
4 0 3

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.

 

 

Replies 8 (8)
Anthony_David_
Trailblazer
229 29 89

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
drakedev
Shopify Partner
601 129 165

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 my answer was helpful click Like to say thanks
If the problem is solved remember to click Accept Solution
Shopify/Shopify Plus custom development: You can hire me for simple and/or complex tasks.
50451
Tourist
4 0 3

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 }}

 

drakedev
Shopify Partner
601 129 165

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 my answer was helpful click Like to say thanks
If the problem is solved remember to click Accept Solution
Shopify/Shopify Plus custom development: You can hire me for simple and/or complex tasks.
tekhaus
Shopify Partner
5 0 1

And none of these methods appear to work within email notifications. @Shopify, what is the correct way to generate a PDF file_reference url within an order notification template?

 

{{ line.product.metafields.my_fields.manual }} => "gid://shopify/GenericFile/22826941284522"

{{ line.product.metafields.my_fields.manual | file_url }} => "https://cdn.shopify.com/s/files/1/0534/2560/2730/files/gid://shopify/GenericFile/22826941284522?113"

{{ line.product.metafields.my_fields.manual.url }} => null

{{ line.product.metafields.my_fields.manual.url | file_url }} => "https://cdn.shopify.com/s/files/1/0534/2560/2730/files/?113"

 

Verdant-Spark
Shopify Partner
89 8 23

Did  you ever get a resolution to this?

brendamarienyc
Tourist
3 0 1

I am having this problem as well, and have tried everything suggested in this thread. Sometimes the below liquid works as expected and it creates a url link to the file (a pdf in my case), but most of the time I get a liquid error that reads "Liquid error (sections/main-product.liquid line 310): internal".

{{ product.metafields.my_fields.tear_sheet | file_url }}

 

Danh11
Tourist
9 0 1

Also getting this problem. Appending '.url' on the end of the metafield path doesn't work as expected. Putting it through the 'file_url' filter does work.