Skip to content

Instantly share code, notes, and snippets.

@clayg
Created June 11, 2014 22:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clayg/ae43968b46022ef79235 to your computer and use it in GitHub Desktop.
Save clayg/ae43968b46022ef79235 to your computer and use it in GitHub Desktop.
upload a static large object
import sys
from hashlib import md5
from swiftclient.client import get_auth, put_container, put_object
from swift.common.utils import json
def write_part(url, token, container, i):
body = 'VERIFY%0.2d' % i + '\x00' * 1048576
part_name = 'manifest_part_%0.2d' % i
manifest_entry = {
"path": "/%s/%s" % (container, part_name),
"etag": md5(body).hexdigest(),
"size_bytes": len(body),
}
put_object(url, token, container, part_name, contents=body)
return manifest_entry
def main():
url, token = get_auth('http://127.0.0.1:8080/auth/v1.0', 'test:tester',
'testing')
container = 'simple-slo'
put_container(url, token, container)
manifest_data = []
for i in range(10):
manifest_entry = write_part(url, token, container, i)
manifest_data.append(manifest_entry)
put_object(url, token, container, 'manifest',
contents=json.dumps(manifest_data),
query_string='multipart-manifest=put')
if __name__ == "__main__":
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment