Using media filters on metafield file type

Hi,

I have the following:

{% assign product_image = product.selected_or_first_available_variant.metafields.my_fields.image_1 %}

According to this link https://shopify.dev/api/liquid/objects/generic-file I should be able to do {{ product_image.media_type }} but this doesn’t return anything.

Does anyone know if what I am trying to do is possible?

Kind regards
Michael

Hi @molten_frog ,

Please change code:

{% assign product_image = product.selected_or_first_available_variant.metafields.my_fields.image_1 %}

=>

{% assign product_image = product.selected_or_first_available_variant.metafields.my_fields.image_1.value %}

Hope it helps!

You are an absolute hero. Not the first time you have helped me :slightly_smiling_face:

Hi @molten_frog ,

If you have any difficulty, you can contact me.

Happy to help you.

Thanks @LitExtension I really appreciate it.

I have uploaded an mp4 to variant_media_1. And similar to the code above I have done the following:

{% assign product_video = product.selected_or_first_available_variant.metafields.my_fields.variant_media_1.value %}

However, product_video.media_type returns generic_file rather than video?

Hi @molten_frog ,

The generic_file object can be returned when a metafield has a file_reference type. If the file_reference is not an image of type JPEG, PNG, or GIF, then it will return a generic_file.

Refer https://i.imgur.com/8iiOqCc.png

Hope it is clear to you.