Created
June 19, 2015 20:04
-
-
Save ctoth/7bd8b32215b4eae73439 to your computer and use it in GitHub Desktop.
Uploading with Poster
This file contains hidden or 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
| import os | |
| import urllib2, poster.streaminghttp | |
| from poster.encode import multipart_encode | |
| opener = poster.streaminghttp.register_openers() | |
| def upload(filename, url, key='file', user_agent='HTTP Uploader', callback=None): | |
| with open(filename, 'rb') as to_upload: | |
| datagen, headers = multipart_encode({key: to_upload}, cb=callback) | |
| req = urllib2.Request(url, datagen, headers) | |
| return urllib2.urlopen(req).read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment