Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returned ETag for uploaded entities #244

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion s3transfer/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,17 @@ def _main(self, client, bucket, key, upload_id, parts, extra_args):
``UploadPartTask.main()``.
:param extra_args: A dictionary of any extra arguments that may be
used in completing the multipart transfer.
:returns: A dictionary representing metadata information about the
upload, such as the ETag for the uploaded entity.
"""
client.complete_multipart_upload(
response = client.complete_multipart_upload(
Bucket=bucket,
Key=key,
UploadId=upload_id,
MultipartUpload={'Parts': parts},
**extra_args,
)
metadata = dict()
if 'ETag' in response:
metadata['ETag'] = response['ETag']
return metadata
9 changes: 8 additions & 1 deletion s3transfer/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,16 @@ def _main(self, client, fileobj, bucket, key, extra_args):
:param key: The name of the key to upload to
:param extra_args: A dictionary of any extra arguments that may be
used in the upload.
:returns: A dictionary representing metadata information about the
upload, such as the ETag for the uploaded entity.
"""
with fileobj as body:
client.put_object(Bucket=bucket, Key=key, Body=body, **extra_args)
response = client.put_object(Bucket=bucket, Key=key, Body=body,
**extra_args)
metadata = dict()
if 'ETag' in response:
metadata['ETag'] = response['ETag']
return metadata


class UploadPartTask(Task):
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,8 @@ def test_main(self):
class TestCompleteMultipartUploadTask(BaseMultipartTaskTest):
def test_main(self):
upload_id = 'my-id'
parts = [{'ETag': 'etag', 'PartNumber': 0}]
parts = [{'ETag': 'part-etag', 'PartNumber': 0}]
etag = 'uploaded-etag'
task = self.get_task(
CompleteMultipartUploadTask,
main_kwargs={
Expand All @@ -793,15 +794,17 @@ def test_main(self):
)
self.stubber.add_response(
method='complete_multipart_upload',
service_response={},
service_response={'ETag': etag},
expected_params={
'Bucket': self.bucket,
'Key': self.key,
'UploadId': upload_id,
'MultipartUpload': {'Parts': parts},
},
)
task()
task_response = task()
self.assertIn("ETag", task_response)
self.assertEqual(task_response["ETag"], etag)
self.stubber.assert_no_pending_responses()

def test_includes_extra_args(self):
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ def test_submits_tag_for_multipart_fileobj(self):
class TestPutObjectTask(BaseUploadTest):
def test_main(self):
extra_args = {'Metadata': {'foo': 'bar'}}
etag = 'uploaded-etag'
with open(self.filename, 'rb') as fileobj:
task = self.get_task(
PutObjectTask,
Expand All @@ -644,15 +645,17 @@ def test_main(self):
)
self.stubber.add_response(
method='put_object',
service_response={},
service_response={'ETag': etag},
expected_params={
'Body': ANY,
'Bucket': self.bucket,
'Key': self.key,
'Metadata': {'foo': 'bar'},
},
)
task()
task_response = task()
self.assertIn("ETag", task_response)
self.assertEqual(task_response["ETag"], etag)
self.stubber.assert_no_pending_responses()
self.assertEqual(self.sent_bodies, [self.content])

Expand Down