import math from pathlib import Path import requests from tests.integration.client import PresignedURLPart, PresignedURLResponse def upload( *, path: Path, presigned_urls: list[PresignedURLPart] ) -> list[PresignedURLResponse]: """ Uploads the file located at `path` to S3 using provided presigned URLs. Returns: A list of dictionaries containing part numbers and their corresponding ETags. """ part_count = len(presigned_urls) chunk_size = math.ceil(path.stat().st_size / part_count) parts: list[PresignedURLResponse] = [] with path.open("rb") as file: for presigned_url in presigned_urls: data = file.read(chunk_size) if not data: break response = requests.put(presigned_url["url"], data=data) response.raise_for_status() parts.append( { "part_number": presigned_url["part_number"], "etag": response.headers.get("ETag", ""), } ) return parts