Can we retrieve a metafields file name?

Shopify Partner
19 0 0

Hi @Niki_K ,


Is it possible to return a metafields file name?


Screenshot 2022-09-21 at 15.11.29.png

Reply 1 (1)

Shopify Partner
448 46 125

Hey @LloydSpencer,


sure, not that easy, but still you can get a way around it. 😄 


Limitations: My solution works for files, which are stored in pdf. You might need to edit the code if you use other file types. 


I saved my file as Color Guide. (Shopify adds underscore instead of space, so I needed to replace the underscore with a space back). Here's my solution:


  {% for file in product.metafields.custom.file.value %}
    {% assign file_name_initial = file.url | split: '/' | last %} <!-- you get the file name with the file format and additional information -->
    {% assign file_name_long = file_name_initial | split: '.pdf' | first %} <!-- you get rid of the additional information -->
    {% assign file_name = file_name_long | replace: "_", " " %} <!-- you replace underscore with a space -->
      <a href="{{ file.url }}" target="_blank">{{ file_name }}</a>
  {%- endfor -%}


And here's how it will be rendered:  

Snímek obrazovky 2022-09-21 v 16.52.07.png

Is it what you're looking for? 


Let me know if you need further help! 🙂

Send me a link to your store to and I'll help you out.
For more info what I do, visit my agency website or my personal website