Created
November 25, 2014 16:21
-
-
Save DrGonzo/02dc8f240a1e9dcaa342 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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