Liquid, JavaScript, themes, sales channels
Trying to figure out how to force download a video I uploaded to metafield.
PDF download works as expected, it's just videos and images, they just open and play on new tab instead (I tried removing target="_blank" but they just play on the same tab instead).
I've appended download attribute to the link, but it didn't do anything.
<a class="button" target="_blank" download="{{ file_name }}" title="{{ file_name }}" href="{{ list.sources[1].url }}">DOWNLOAD</a>
Any little bits of help is appreciated.
Hello @drsw
The download attribute only works if the image/video URLs are in the same domain of your store.
I see. Is there a way to force the url to come from the same domain then?
I tried to use asset_url filter but it's not working.
I can get the link for pdfs simply by using .url param, but it doesn't work with images and videos. This is how I 'hack' the loop:
{% for list in product.metafields.productDetails.customer_files.value %}
{% capture indicator %}{{ list }}{% endcapture %}
...
<a class="button" target="_blank" download={{ file_name }} title={{ file_name }} href="
{% case indicator %}
{% when 'GenericFileDrop' %}
{{ list.url }}
{% when 'VideoDrop' %}
{{ list.sources[1].url }}
{% else %}
https://cdn.shopify.com/s/files/1/0775/6306/8702/{{ list }}
{% endcase %}
">DOWNLOAD</a>
...
{% endfor %}
Actually looking at it again, I don't understand why the pdfs can output the same domain as my store, while the videos get cdn.shopify.com.
That is how Shopify stores and distributes assets. PDF files are saved on your store, while images/videos are served on Shopify global CDN.
User | RANK |
---|---|
37 | |
29 | |
13 | |
12 | |
9 |
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023