473,394 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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).info()).

Sep 4 '06 #1
2 6093
dc****@gmail.com 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%20stingray%201%20.JPG'
proxy = 'proxy02:8080'
import httplib
c = httplib.HTTPConnection(proxy)
c.request('GET', url)
resp = c.getresponse()
for k in resp.msg.keys():
.... print resp.msg.getallmatchingheaders(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\xe0\x00\x10JFIF\x00\x01\x02\x02\x00\ x00\x00\x00\x00\x00\xff\xe1\x057Exif\x00\x00II*\x0 0\x08\x00\x00\x00\t\x00\x0f\x01\x02\x00\x06\x00\x0 0\x00z\x00\x00\x00\x10\x01\x02\x00\x13\x00\x00\x00 \x80\x00\x00\x00\x12\x01\x03\x00\x01\x00\x00\x00\x 01\x00\x00\x00\x1a\x01\x05\x00\x01\x00\x00\x00\x93 \x00\x00\x00\x1b\x01\x05\x00\x01\x00\x00\x00\x9b\x 00\x00\x00'
>>resp.fp.close()
Sep 5 '06 #2

Justin Ezequiel wrote:
dc****@gmail.com 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
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...
2
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
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;...
21
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...
0
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...
6
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:...
1
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...
3
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...
0
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...
3
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.