0

My website, which is hosted on AWS EC2 allows files stored in AWS S3 to be downloaded. The download link is something like this.

<a href="https://example.s3.us-east-2.amazonaws.com/client/attachments/160/uBhl0qvQjfdYUN1j.docx" download="My_download_file"></a>

The link works, but the file is downloaded with the original filename (e.g. uBhl0qvQjfdYUN1j.docx). I want to download the file with a specified name, e.g. My_downlaod_file or My_download_file.docx. Specifying extension with "download" does not help:

<a href="https://example.s3.us-east-2.amazonaws.com/client/attachments/160/k8J98BYnmMyUnQlSkTYGKViEuBhl0qvQjfdYUN1j.docx" download="downloadfile.docx"></a>

However, when I use the a tag to download a file that is available on the server (my server on AWS EC2 as well as my local server on my Mac), it works:

 <a href="images/COTA-HORIZONTAL-350px.png" download="my_download">AAAA</a>

The above code downloads COTA-HORIZONTAL-350px.png as my_download.png.

It appears that the issue is related to a file that is being downloaded from AWS S3. Is this anything to do with 'same-origin-policy' or AWS-S3 issue, or I am missing something?

user761100
  • 2,171
  • 4
  • 23
  • 31
  • Do your items include a `Content-Disposition` header? If so, it'll take precedence over the download attribute on the link. – Anon Coward Sep 18 '22 at 00:33
  • @AnonCoward, I am not using any Content-Disposition in my project. (I did not find 'Content-Disposition' through Search in my Laravel project, though it found node_modules/content-disposition and node_modules/content-disposition/node_modules/safe-buffer in package-lock.json -- I don't know if that would cause any issue) – user761100 Sep 18 '22 at 16:14
  • The `download` attribute doesn't work across origins. The file downloads because it is a `docx` and your browser doesn't have a plugin to try to display it inline. – Quentin Sep 18 '22 at 18:52

0 Answers0