Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created February 27, 2013 06:40
Show Gist options
  • Save chmouel/5045714 to your computer and use it in GitHub Desktop.
Save chmouel/5045714 to your computer and use it in GitHub Desktop.
# test_client.py
import hmac
from time import time
from hashlib import sha1
import requests
MODE = "VM"
#var
CONF = {
'VM': {
'account_formdata_key': 'foobar',
'account': '5dbdc523ea824cc190a7862b3fc4fdfe',
'container': 'foobar',
'host': 'vm:8080',
'htmethod': 'http',
'redirect': 'http://google.com',
}
}
#const
max_file_count = 2
max_file_size = 1073741824
seconds = 86400
#other
expires = int(time() + int(seconds))
path = "v1/AUTH_%(account)s/%(container)s/" % CONF[MODE]
upload_url = '%s://%s/%s' % (CONF[MODE]['htmethod'],
CONF[MODE]['host'],
path)
signature = hmac.new(CONF[MODE]['account_formdata_key'],
'/%s\n%s\n%s\n%s\n%s' % (path,
CONF[MODE]['redirect'],
max_file_size,
max_file_count,
expires),
sha1).hexdigest()
data = {
'max_file_size': max_file_size,
'max_file_count': max_file_count,
'expires': expires,
'signature': signature,
'redirect': CONF[MODE]['redirect'],
}
files = {
'file1': ('sample-file.big', open("/tmp/sample-file.big", "rb")),
}
r = requests.post(upload_url, files=files, data=data)
print r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment