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.
- Python - Tkinter askquestion Dialog
- PyQt5 Input Dialog | Python
- Python - Raise elements of tuple as power to another tuple
- Python - Tkinter Choose color Dialog
- How to download Google Images using Python
- Download Instagram profile pic using Python
- Download and Install Python 3 Latest Version
- Simple Multithreaded Download Manager in Python
- YouTube Media/Audio Download using Python | pafy
- Python | Download YouTube videos using youtube_dl module
- Python | How to download windows lock-screen wallpapers
- How to download and install Python Latest Version on Android
- How to download and install Python Latest Version on Windows
- How to download and install Python Latest Version on macOS / Mac OS X
- Pytube | Python library to download youtube videos
- Python | Program to download complete Youtube playlist
- How to download and install Python Latest Version on Linux
- Python program to reverse the content of a file and store it in another file
- Create a GUI to convert CSV file into excel file using Python
- reStructuredText | .rst file to HTML file using Python for Documentations
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.