Created
January 26, 2024 14:04
-
-
Save renini/b3a2ecae0e5cac7df3cd5f2adcf0d7e1 to your computer and use it in GitHub Desktop.
upload_mp4_files_to_s3_test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import boto3 | |
from tqdm import tqdm | |
def upload_mp4_files_to_s3(bucket_name: str, local_directory: str, access_key_id: str, secret_access_key: str): | |
session = boto3.Session( | |
aws_access_key_id=access_key, | |
aws_secret_access_key=secret_key | |
) | |
s3 = session.resource('s3', endpoint_url='http://storage.path:9000') | |
print(s3) | |
for root, dirs, files in os.walk(local_directory): | |
print(files) | |
for file in files: | |
if file.endswith('.mp4'): | |
file_path = os.path.join(root, file) | |
s3_path = os.path.join(root, file).replace(local_directory, '') | |
with tqdm(total=os.path.getsize(file_path), unit='B', unit_scale=True, desc=file) as progress_bar: | |
s3.meta.client.upload_file(file_path, bucket_name, s3_path, Callback=lambda bytes_transferred: progress_bar.update(bytes_transferred)) | |
# Example usage | |
bucket_name = 'testbucket' | |
local_directory = '/path/to/mediatestmp4' | |
access_key = '' | |
secret_key = '' | |
upload_mp4_files_to_s3(bucket_name, local_directory, access_key, secret_key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment