更新s3bucket python中文件夹中的文件



我在s3 bucket中有一个文件夹,我需要更新现有文件夹中的文件使用python可以帮助

我找到了自己问题的答案。下面的代码运行良好从我的本地文件夹。我打开文件夹并使用"rb"(读取二进制文件(来存储文件。

s3 = boto3.client(
's3', 
region_name='ap-south-1', 
aws_access_key_id = S3_access_key, 
aws_secret_access_key=S3_secret_key
)
path_data=os.path.join(MEDIA_ROOT, "screenShots",folder_name)
dir=os.listdir(path_data)
for file in dir:
with open(path_data+"/"+file, 'rb') as data:
s3.upload_fileobj(data, s3_Bucket_name, folder_name+"/"+file)
shutil.rmtree(path_data)

最新更新