Created
April 13, 2012 20:08
-
-
Save sasimpson/2379765 to your computer and use it in GitHub Desktop.
upload a static blog directory named 'output' to a container named 'blog'
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
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