Skip to content

Instantly share code, notes, and snippets.

@sasimpson
Created April 13, 2012 20:08
Show Gist options
  • Save sasimpson/2379765 to your computer and use it in GitHub Desktop.
Save sasimpson/2379765 to your computer and use it in GitHub Desktop.
upload a static blog directory named 'output' to a container named 'blog'
import mimetypes
import requests
import cloudauth
import os
import re
token, storage_url = cloudauth.getauth('object-store')
headers = {'x-auth-token': token}
regexp = re.compile('./output/')
for r,d,f in os.walk('./output'):
for x in f:
obj_name = regexp.sub('',"%s/%s" % (r, x))
file_name = "%s/%s" % (r, x)
fp = open(file_name)
data = fp.read()
fp.close()
obj_path = '%s/blog/%s' % (storage_url, obj_name)
headers['content-type'] = mimetypes.guess_type(obj_name)[0]
print obj_path, len(data)
resp2 = requests.put(obj_path, data=data, headers=headers)
if resp2.ok:
print "ok"
else:
print "not ok %s" % resp2.status_code
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment