简体   繁体   中英

Upload file in S3 using boto3 with Dynamic Foldername

I have 4 S3 buckets : SourceBucket\\folder1\\file1 and DestinationBucket1-folder1, SourceBucket\\folder2\\file1 and DestinationBucket2-folder2. When I upload the folders, I would like the code to check for folder 'DestinationBucket1-folder1' if it exists and then upload the folder1 and files underneath that folder.

I am struggling with S3 KEY. How can I parse S3 KEY and check if the specifice folder exist and then upload the first folder under SourceBucket?

The below code creates the folder if not present and uploads the file:

s3 = boto3.resource('s3', region_name='us-east-2', aws_access_key_id=access_id, aws_secret_access_key=access_key)
s3.meta.client.upload_file(filePath, backet-name, str(foldername) + "/" + str(sub-foldername) + "/" + filename)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM