My website is called www.example.com, and I keep my files in a storage bucket called storage.example.com.
Each file has a hash-like filename in the bucket (to prevent scrapers), but I would like to rename this to something sensible when a user clicks the download link from www.example.com.
In the old days, you used to be able to use the download
attribute within <a>
, however, the MDN docs say that this only works for same-origin URLs, and storage.example.com is considered to be different. This means that download
attribute is ignored, and the default hash-like filename is used.
Is there an easy way to do this in 2022? Many answers like this are written before modern browsers started blocking the desired behavior. I understand that it seems like I am trying to bypass a security feature, so I am also open to suggestions that achieve the same outcome while not compromising security.
Note: the files are small zip files (~30kB), so a solution that downloads, renames then presents the result to the user would work.