Created
November 10, 2020 17:56
-
-
Save amacal/7e85c6956bc960a08ad798c4b3e4a64b to your computer and use it in GitHub Desktop.
This file contains 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 boto3 | |
parts = list() | |
chunksize = 32 * 1024 * 1024 | |
filename = 'enwiki-20201020-langlinks.sql.gz' | |
s3client = boto3.client('s3') | |
with open(filename, 'rb') as fp: | |
part = 1 | |
upload = s3client.create_multipart_upload(Bucket='la-labs-279215538049', Key=filename) | |
print(f'Upload started {upload["UploadId"]} ...') | |
while chunk := fp.read(chunksize): | |
response = s3client.upload_part(Bucket='la-labs-279215538049', Key=filename, UploadId=upload['UploadId'], PartNumber=part, Body=chunk) | |
parts.append({'ETag':response['ETag'], 'PartNumber':part}) | |
print(f'Part {part} completed with {response["ETag"]}') | |
part = part + 1 | |
s3client.complete_multipart_upload(Bucket='la-labs-279215538049', Key=filename, UploadId=upload['UploadId'], MultipartUpload={'Parts':parts}) | |
print(f'Upload completed {upload["UploadId"]}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment