Skip to content

Commit

Permalink
Upload to S3: support object name starting with s3://bucket_name/ for…
Browse files Browse the repository at this point in the history
… upload (#827)

* add capability to download file from s3

* fix flake8 error

* add ability to remove s3://bucketname/ from the object name before upload
  • Loading branch information
cmadjar authored Nov 8, 2022
1 parent f0810cb commit 3644f95
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions python/lib/aws_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ def upload_file(self, file_name, object_name):
"""

# Upload the file
s3_prefix = f"s3://{self.bucket_name}/"
s3_file_name = object_name[len(s3_prefix):] if object_name.startswith(s3_prefix) else object_name

try:
print(f"Uploading {object_name} to {self.aws_endpoint_url}/{self.bucket_name}")
self.s3_bucket_obj.upload_file(file_name, object_name)
print(f"Uploading {s3_file_name} to {self.aws_endpoint_url}/{self.bucket_name}")
self.s3_bucket_obj.upload_file(file_name, s3_file_name)
except ClientError as err:
raise Exception(f"{file_name} upload failure - {format(err)}")

Expand Down

0 comments on commit 3644f95

Please sign in to comment.