Home > Mobile >  Know when upload to s3 bucket is complete
Know when upload to s3 bucket is complete

Time:12-18

I am using boto3 to upload an image to my s3 bucket and the below proccess works fine. What I want is, how can I know when the upload process is complete. Maybe print 'upload complete' when done. How can I achieve this? Thanks in advance.

import boto3
s3 = boto3.resource('s3')

file = open(imagePath, 'rb')
object = s3.Object('s3BucketName', fileName)
ret = object.put(Body=file, Metadata={'example': 'test'})
#when complete
print('upload complete')

CodePudding user response:

When the upload is done, it sends a dict type response. Since you're already capturing this in your ret variable, you'd just need to add a condition to check that. You can check the response structure here - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Object.put

Alternatively, a more detailed example which makes use of the s3.object.wait_until_exists() method - https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/python/example_code/s3/s3_basics/object_wrapper.py#L51

  • Related