
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How To Raise a "File Download" Dialog Box in Python?
Sometimes, it is desired that you want to give option where a user can click a link and it will pop up a "File Download" dialogue box to the user instead of displaying actual content. This is very easy and can be achieved through HTTP header. This HTTP header is be different from the header mentioned in previous section.
For example, if you want make a FileName file downloadable from a given link, then its syntax is as follows −
#!/usr/bin/python # HTTP Header print "Content-Type:application/octet-stream; name = \"FileName\"\r\n"; print "Content-Disposition: attachment; filename = \"FileName\"\r\n\n"; # Actual File Content will go here. fo = open("foo.txt", "rb") str = fo.read(); print str # Close opend file fo.close()
Hope you enjoyed this tutorial. If yes, please send me your feedback at: Contact Us
- Related Articles
- How to raise a "File Download" Dialog Box in Python CGI Programming?
- Raise a "File Download" Dialog Box using Perl
- Access to file download dialog in Firefox in Selenium.
- Save File Dialog Box in Tkinter
- How to create Dialog Box in ReactJS?
- How to create a Confirmation Dialog Box in Java?
- How to download a file using Node.js?
- How to create a Custom Dialog box on Android?
- How to create a Dialog Box without a title in Android?
- How do I automatically download files from a pop up dialog using selenium-python?
- How do we define a dialog box in HTML?
- How to add check box list in alert dialog?
- How to work with Alerts Dialog box in ReactNative?
- How to bring a dialog box to appear at the front in a Tkinter module of Python?
- How to download a file from a URL in C#?

Advertisements