initial stage

This commit is contained in:
Giambattista Bloisi 2024-07-02 11:45:36 +02:00
parent 833ea1538a
commit 0339a92de5
1 changed files with 4 additions and 4 deletions

View File

@ -46,6 +46,7 @@ def download_uri(session: requests.Session, url: str, s3_client, bucket, key, ma
response = s3_client.create_multipart_upload(Bucket=bucket,
Key=key)
upload_id = response['UploadId']
tries = 0
while tries < max_retries:
try:
@ -57,13 +58,12 @@ def download_uri(session: requests.Session, url: str, s3_client, bucket, key, ma
chunk_size = max(total_size // (10000 - 1), 15 * 1024 * 1024)
for chunk in r.iter_content(chunk_size=chunk_size):
if chunk:
# Upload part by part to S3
response = s3_client.upload_part(
Body=chunk,
Bucket=bucket,
Key=key,
PartNumber=part_number,
UploadId=response['UploadId']
UploadId=upload_id
)
parts.append({'PartNumber': part_number, 'ETag': response['ETag']})
current_size += len(chunk)
@ -83,14 +83,14 @@ def download_uri(session: requests.Session, url: str, s3_client, bucket, key, ma
s3_client.abort_multipart_upload(
Bucket=bucket,
Key=key,
UploadId=response['UploadId']
UploadId=upload_id
)
raise
s3_client.complete_multipart_upload(
Bucket=bucket,
Key=key,
UploadId=response['UploadId'],
UploadId=upload_id,
MultipartUpload={'Parts': parts}
)