Skip to content

Instantly share code, notes, and snippets.

@DrGonzo
Created November 25, 2014 16:21
Show Gist options
  • Save DrGonzo/02dc8f240a1e9dcaa342 to your computer and use it in GitHub Desktop.
Save DrGonzo/02dc8f240a1e9dcaa342 to your computer and use it in GitHub Desktop.
class FileReader:
def __init__(self, fp):
self.fp = fp
def read_callback(self, size):
return self.fp.read(size)
def curl_upload(f, u):
c = pycurl.Curl()
c.setopt(pycurl.URL, u)
c.setopt(pycurl.UPLOAD, 1)
c.setopt(pycurl.READFUNCTION, FileReader(open(f, 'rb')).read_callback)
filesize = os.path.getsize(f)
c.setopt(pycurl.INFILESIZE, filesize)
c.perform()
status = c.getinfo(pycurl.HTTP_CODE)
c.close()
return status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment