Repository: libcloud Updated Branches: refs/heads/trunk 38111c5ac -> 6338874e1
Add an example which shows to specify meta-data when uploading an object. Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/6338874e Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/6338874e Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/6338874e Branch: refs/heads/trunk Commit: 6338874e1b25c66cfdc05c6821f1fc19e0f6ff1f Parents: 38111c5 Author: Tomaz Muraus <[email protected]> Authored: Sat Feb 15 16:56:09 2014 +0100 Committer: Tomaz Muraus <[email protected]> Committed: Sat Feb 15 16:58:41 2014 +0100 ---------------------------------------------------------------------- docs/examples/storage/upload_with_metadata.py | 17 +++++++++++++++++ docs/storage/examples.rst | 15 ++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/6338874e/docs/examples/storage/upload_with_metadata.py ---------------------------------------------------------------------- diff --git a/docs/examples/storage/upload_with_metadata.py b/docs/examples/storage/upload_with_metadata.py new file mode 100644 index 0000000..907e9ec --- /dev/null +++ b/docs/examples/storage/upload_with_metadata.py @@ -0,0 +1,17 @@ +from libcloud.storage.types import Provider +from libcloud.storage.providers import get_driver + +FILE_PATH = '/home/user/myfile.tar.gz' + +cls = get_driver(Provider.S3) +driver = cls('api key', 'api secret key') + +container = driver.get_container(container_name='my-backups-12345') + +extra = {'meta_data': {'owner': 'myuser', 'created': '2014-02-2'}} + +with open(FILE_PATH, 'rb') as iterator: + obj = driver.upload_object_via_stream(iterator=iterator, + container=container, + object_name='backup.tar.gz', + extra=extra) http://git-wip-us.apache.org/repos/asf/libcloud/blob/6338874e/docs/storage/examples.rst ---------------------------------------------------------------------- diff --git a/docs/storage/examples.rst b/docs/storage/examples.rst index 8b0a6ef..8b0a50f 100644 --- a/docs/storage/examples.rst +++ b/docs/storage/examples.rst @@ -3,13 +3,26 @@ Storage Examples ================ +Specify meta-data when uploading an object +------------------------------------------ + +Most of the providers allow you to associate arbitrary key-value pairs +(meta-data) with every uploaded object. This example shows how to do that in +Libcloud. + +.. literalinclude:: /examples/storage/upload_with_metadata.py + :language: python + +As you can see in the example above, meta-data is specified by including +``meta_data`` key in the ``extra`` dictionary argument which gets passed +to all the upload methods. + Create a backup of a directory and directly stream it to CloudFiles ------------------------------------------------------------------- .. literalinclude:: /examples/storage/create_directory_backup_stream_to_cf.py :language: python - Efficiently download multiple files using gevent ------------------------------------------------
