Create a download link

Hello,

I am trying to create a link so users can download a file from my project. I created the link like this:
Screen Shot 2021-12-23 at 7.53.11 AM

Which resulted in this:

Yet when the link is clicked, the file opens in the browser.

What am I doing wrong?

1 Like

Hello @john

Add the following parameters to the asset URL:

?dl=assetexample.pdf

That would make the url be

https://www.datocms-assets.com/58581/1640218505-assetexample.pdf?dl=assetexample.pdf

This will create a download link for that asset, not a “visualisation link”

The download attribute on the anchor tag is unnecessary, as it doesn’t support CORS download requests

Let me know if this helps!

Bingo! Thank you!

An extension to this question: can you direct me to documentation on how to create a link that is expires, or requires a user to be logged in / have an account / etc?

We don’t have a native solution for that, sorry, but it’s something you can do on your server-side with something like this: files-temp-urls - npm
Or if you prefer you can also implement your own solution

Thank you Marcelo!

1 Like