I currently use the following code to upload one file to a remote server:
import MultipartPostHandler, urllib2, sys
cookies = cookielib.CookieJar()
opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)
params = {"data" : open("foo.bar") }
request=opener.open("http://127.0.0.1/api.php", params)
response = request.read()
This works fine, but for larger files the upload takes some time, and it would be nice to have a callback that allows me to display the upload progress?
I already tried the kodakloader solution, but it does not has a callback for a single file.
Does anyone knows a solution?
I think it’s impossible to know upload progress with urllib2. I’m looking into using pycurl.