Raise a File Download Dialog Box in Python
Raising a File Download Dialog Box for end-user to download files like pdf, media-objects, documents, etc in Python can be done by the use of HTTP Header. It comes in handy where there is a need to develop a feature where instead of showing the files in the browser, the file contains is automatically downloaded.
For instance, if you need a file say (
GeeksForGeeks.txt) to be downloaded on click of a link from the database the code would somewhat look like below:
If you just run the script it will just read the original file as below:
Note: One needs to make sure the file to be downloaded is in the same directory as the Python script.
Using the script in your application:
The below code is a simple example of the use of the above script in an application:
On click of the “Click Here” link the download box would pop up and start downloading the file.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course