Implementing "download image" functionality via setting "Content-Disposition:attachment" (AWS S3 Bucket)

Viewed 45

In a web app of mine (developed via Django/Python framework), I serve images to users via an AWS S3 bucket.

I now want to provide a "download image" button next to each image served on the website.

I understand the best way to do that is to change the Metadata of the Properties of the S3 bucket to Content-Disposition:attachment (guide here: https://docs.easydigitaldownloads.com/article/1172-how-do-i-force-files-to-download-in-amazon-s3)

However, if I do that, all images would default to the download behavior on my web app. I only want to impart this functionality via the download button.

What's my best course of action given the circumstances? I.e. how do I configure the S3 bucket to respond in a way that enables the download button to actually work (while the rest of the web app's functionality remains the same).

Or perhaps, there's an alternative solution to my problem?


Btw, I know about the download attribute of the <a> tag. It works nicely enough, but only if the domain/subdomain, etc of the downloadable resource is the same.

In my case, I'm using an S3 bucket to host my files - the domain is separate from my web app's domain, and hence any <a download> type tags do not work (thus not a viable solution).

0 Answers
Related