This attribute typically only works for same-origin URLs. If the file is hosted on a different domain (like an S3 bucket), the browser may ignore the attribute and open the file anyway.
The simplest method is adding the download attribute to an HTML anchor ( ) tag.
Content-Disposition: attachment; filename="example.pdf" : This forces the browser to open a "Save As" dialog. Programmatically downloading files in the browser
Using tells the browser to save the file rather than open it.
For a more robust solution, servers can send an HTTP header that explicitly dictates how the file should be handled.