Python: HTTP Post a large file with streaming

Posted by Daniel Von Fange on Stack Overflow See other posts from Stack Overflow or by Daniel Von Fange
Published on 2010-03-23T18:31:57Z Indexed on 2010/03/23 18:43 UTC
Read the original article Hit count: 268

Filed under:
|
|

I'm uploading potentially large files to a web server. Currently I'm doing this:

import urllib2

f = open('somelargefile.zip','rb')
request = urllib2.Request(url,f.read())
request.add_header("Content-Type", "application/zip")
response = urllib2.urlopen(request)

However, this reads the entire file's contents into memory before posting it. How can I have it stream the file to the server?

© Stack Overflow or respective owner

Related posts about python

Related posts about urllib2