user6611771
user6611771

Reputation:

How to download video from S3 using python?

I have the following algorithm

import boto3

AWS_ACCESS_KEY_ID = '...'
AWS_SECRET_ACCESS_KEY = '...'

s3_client = boto3.client('s3',
                         aws_access_key_id=AWS_ACCESS_KEY_ID,
                         aws_secret_access_key= AWS_SECRET_ACCESS_KEY)
bucket_name = '...'
prefix = '...'

# List all objects within a S3 bucket path
response = s3_client.list_objects(Bucket = bucket_name, Prefix = prefix)
for file in response['Contents']:
    name = file['Key'].rsplit('/', 1)
    print name

After the execution I see:

1909132317.mp4
1909151647.mp4
...

So, I have an access to the videos. How can I download them to the local folder in my Mac? Please, help me.

Upvotes: 2

Views: 4063

Answers (1)

franklinsijo
franklinsijo

Reputation: 18270

Use the download_file() method to download the objects,

response = s3_client.list_objects(Bucket=bucket_name, Prefix=prefix)
for file in response['Contents']:
    name = file['Key'].rsplit('/', 1)
    s3_client.download_file(Bucket=bucket_name, Prefix=file['Key'], Filename='/localpath/'+name)

Upvotes: 1

Related Questions