Skip to content

Instantly share code, notes, and snippets.

@ctoth
Created June 19, 2015 20:04
Show Gist options
  • Select an option

  • Save ctoth/7bd8b32215b4eae73439 to your computer and use it in GitHub Desktop.

Select an option

Save ctoth/7bd8b32215b4eae73439 to your computer and use it in GitHub Desktop.
Uploading with Poster
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