473,574 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using "Content-Disposition" in HTTP download

What is the correct way to download a file through HTTP and save it to
the file name suggested by "Content-Disposition"?

I would use urlretrieve but I'm not sure how to obtain the file name
through the HTTP headers without downloading the body (e.g.
urlopen(url).in fo()).

Sep 4 '06 #1
2 6112
dc****@gmail.co m wrote:
What is the correct way to download a file through HTTP and save it to
the file name suggested by "Content-Disposition"?
Perhaps something along the lines of the following?
>>url = r'http://www.4so9.com/cauca/files/ban-doc/francois/stingray/198%20lb%20stin gray%201%20.JPG '
proxy = 'proxy02:8080'
import httplib
c = httplib.HTTPCon nection(proxy)
c.request('GE T', url)
resp = c.getresponse()
for k in resp.msg.keys() :
.... print resp.msg.getall matchingheaders (k)
....
['Content-Length: 64632\r\n']
['Proxy-Connection: close\r\n']
['X-Cache: HIT from SPSweb\r\n']
['Accept-Ranges: bytes\r\n']
['Server: Apache/2.0.51 (Fedora)\r\n']
['Last-Modified: Fri, 03 Dec 2004 16:57:30 GMT\r\n']
['ETag: "3b2375-fc78-8c13280"\r\n']
['Date: Tue, 05 Sep 2006 10:35:48 GMT\r\n']
['Content-Type: image/jpeg\r\n']
['Age: 31440\r\n']
>>data = resp.fp.read()
len(data)
64632
>>data[:100]
'\xff\xd8\xff\x e0\x00\x10JFIF\ x00\x01\x02\x02 \x00\x00\x00\x0 0\x00\x00\xff\x e1\x057Exif\x00 \x00II*\x00\x08 \x00\x00\x00\t\ x00\x0f\x01\x02 \x00\x06\x00\x0 0\x00z\x00\x00\ x00\x10\x01\x02 \x00\x13\x00\x0 0\x00\x80\x00\x 00\x00\x12\x01\ x03\x00\x01\x00 \x00\x00\x01\x0 0\x00\x00\x1a\x 01\x05\x00\x01\ x00\x00\x00\x93 \x00\x00\x00\x1 b\x01\x05\x00\x 01\x00\x00\x00\ x9b\x00\x00\x00 '
>>resp.fp.close ()
Sep 5 '06 #2

Justin Ezequiel wrote:
dc****@gmail.co m wrote:
What is the correct way to download a file through HTTP and save it to
the file name suggested by "Content-Disposition"?

Perhaps something along the lines of the following?
<snip>

Thank you kindly.

Sep 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3102
by: Justin | last post by:
I have a program that downloads files from the web. There are instances in which a .info() will not return a "Content-length" header to me. Is ther a way to specifically request this header or FORCE it to be sent? I know there is some way to get the file size for these files because Internet Explorer is capable of determining the size on a...
2
20004
by: Todd Anderson | last post by:
I'm ussing this <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> to keep me html page from caching. But it's not working. Is there a javascript that will do this? Thanks in advance for your help.
10
7133
by: Michael Strorm | last post by:
Hi! I've been having problems with a DTD. Having had the Sun XML validator reject a document, I put it through 'xmllint' for more information. 'Xmllint' noted a problem with the DTD itself; "validity error : Content model of section is not determinist: (text , (list , text)* , list?)" Here's a very simplified version of the DTD...
21
21251
by: cman | last post by:
does anyone know why i can't generate images with: header("Content-type:image/jpeg"); imagejpeg($img_number); i've tried different examples but i always get a text output as if the header doesn't make a difference at all. <?php //random_number.php $img_number = imagecreate(100,50);
0
1549
by: Kevin Frey | last post by:
We have a data-centric application where all of the "layout" for each data centric page is to be codified (ie. it is expressed in C# code rather than being expressed declaratively). This codification subsequently produces the required web-controls for a page based on whether the page is eg. in view or update mode, examination of the user's...
6
1667
by: Lord0 | last post by:
Hi there, How do I define in a schema that an element (<element>) may have any content i.e. text, other elements, partial elements, angle brackets etc? So all of the following would be valid: <element> aaaaaaa<foo/>bbbbbb<bar/>cccccc
1
2270
by: dave8421 | last post by:
Hi, I'm trying to make sense of the definition for "Rendered Content" in current CR for CSS 2.1 Is rendered content what is displayed on the particular media or device? from the definitions, I got the impression that the rendered content is referring to the source document and not the particular
3
7044
by: Alexander Smirnov | last post by:
I'm developing asp.net 2 web application and need to make a custom http handler which sometime must send response with "204 No Content" code. I set HttpResponse.Status="204 No Content"; But asp automatically adds headers such as "Content-Length: 0". This causes an error on the client. HttpResponse.ClearHeaders() doesn't help. How to make asp...
0
1266
by: wizofaus | last post by:
If you use your browser to navigate to http://www.fsa.gov.uk/register/, it will redirect you to http://www.fsa.gov.uk/register/home.do;jessionid= etc. etc. etc. But if you use WebRequest to fetch that initial URL, the response URL is "http://xdsapvip:3006/register/WEB-INF/jsp/layouts/base.jsp"! This is actually the content of the HTTP...
3
2395
by: K Viltersten | last post by:
I've been informed that a webserver sending a XML file is supposed to add "Content-Type: text/xml header". I'm not questioning that infromation but i'm unsure what was ment by it. The XML i get on my screen when i type in the url to it looks as follows. <?xml version="1.0" encoding="UTF-8"?>
0
7803
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8230
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7810
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5618
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3749
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1337
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1056
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.