Product Generic File URL can't be accessed via liquid

Hey!

We’re having instruction manuals added to every product via a generic file metafield. The files are PDF format, and being uploaded to every product automatically.

I want to display a download button for these PDF-s on each product page, but I’m having a hard time referencing the dynamic object.

I’ve created the {{ product.metafields.custom.manual }} dynamic object on the page, but I’m getting a gid link back: gid://shopify/GenericFile/353XXXXXXXXXX

This can’t be used to download files.

I’ve tried using the | file_url filter ( {{ product.metafields.custom.manual | file_url}} ), but I’m still getting a not valid URL: cdn.shopify.com/s/files/1/0XX0/5XX7/4XX7/files/["gid://shopify/GenericFile/3639XXXXXXXXX]?162

I’ve also tried parsing the .value.url to the metafield like so: {{ product.metafields.custom.manual.value.url }}, but I’m only getting a blank result with this.

The file is indeed attached to said product, and the PDF can be downloaded from the file manager, so the file exists.

How am I meant to grab the actual URL of the uploaded PDF file?

EDIT: I’ve also tried accessing said product’s information via an API call, but I only get a GID link on the API call too

“namespace” => “custom”
“key” => “guide”
“value” => “gid://shopify/GenericFile/353XXXXXXXXXX”

Did you find a solution for this? I have the same problem with email confirmations.
Im pretty sure it worked with value.url before.

This may be a bit late now, but for anyone who stumbles across this topic, this is how I solved the problem in a custom theme block in liquid:

{%- for field in product.metafields.download -%}

{%- assign current_metafield = field | last -%}
{%- assign my_file = current_metafield.value -%}

{%- if my_file.url != blank -%}

<a href="{{ my_file.url }}" target="_blank">Show PDF Document</a>

{%- endif -%}
{%- endfor -%}

Explanation:

  1. First we loop over all metafields. In my case all “download” metafields
  2. Assign the current metafield to “current_metafield“. This is our metafield handle
  3. Assign the current metafields value to “my_file”. This is our file handle
  4. We check for an existing file cdn url. If there is none, dont show the whole block
  5. Output the file cdn url in the a-tag

Hope this helps someone!