From 8274917ee6245f3df6c7aeac5c84880dc3cc4737 Mon Sep 17 00:00:00 2001 From: Rick Ross Date: Tue, 5 Dec 2023 12:59:38 -0800 Subject: [PATCH] Added put_object() for pushing data into a file key in S3 --- lib_afc_s3storage/s3storage.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib_afc_s3storage/s3storage.py b/lib_afc_s3storage/s3storage.py index f457f52..09092cd 100755 --- a/lib_afc_s3storage/s3storage.py +++ b/lib_afc_s3storage/s3storage.py @@ -139,6 +139,37 @@ class S3Storage: return this_object['Body'] + def put_object( self, bucket=None, key=None, data=None ): + """ + put_object + """ + + if bucket == None: + raise AFS3Error("S3Storage.put_object(): missing required bucket name") + + if key == None: + raise AFS3Error("S3Storage.put_object(): missing required key") + + if data == None: + raise AFS3Error("S3Storage.put_object(): missing required data") + + response = self.client.put_object(Bucket=bucket, Key=key, Body=data) + + # response looks like this: + # response = {'ResponseMetadata': + # {'RequestId': 'tx00000ed21e851e5b2e313-00656c222c-32c0e88-default', 'HostId': '', 'HTTPStatusCode': 200, + # 'HTTPHeaders': {'date': 'Sun, 03 Dec 2023 06:37:32 GMT', + # 'content-length': '0', + # 'connection': 'keep-alive', + # 'etag': '"5d6ef8943a9f853a82247c9e87152c1f"', + # 'accept-ranges': 'bytes', + # 'x-amz-request-id': 'tx00000ed21e851e5b2e313-00656c222c-32c0e88-default'}, + # 'RetryAttempts': 0}, + # 'ETag': '"5d6ef8943a9f853a82247c9e87152c1f"'} + + return response + + def delete_all_objects( self, bucket=None ): """ delete_all_objects