Content-Disposition: attachment; filename="example.pdf" : This forces the browser to open a "Save As" dialog. Programmatically downloading files in the browser
Content-Disposition: inline : The browser tries to display the file (default).
For a more robust solution, servers can send an HTTP header that explicitly dictates how the file should be handled.
The simplest method is adding the download attribute to an HTML anchor ( ) tag.
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.
By default, modern browsers prefer to open "viewable" files—such as PDFs, images, or text documents—directly in a new tab or window instead of initiating a download. Developers have two primary ways to override this behavior:
Content-Disposition: attachment; filename="example.pdf" : This forces the browser to open a "Save As" dialog. Programmatically downloading files in the browser
Content-Disposition: inline : The browser tries to display the file (default).
For a more robust solution, servers can send an HTTP header that explicitly dictates how the file should be handled.
The simplest method is adding the download attribute to an HTML anchor ( ) tag.
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.
By default, modern browsers prefer to open "viewable" files—such as PDFs, images, or text documents—directly in a new tab or window instead of initiating a download. Developers have two primary ways to override this behavior: