Skip to content

Commit a691860

Browse files
committed
Create helper function to upload a single file to an AWS S3 bucket.
1 parent 76da170 commit a691860

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/openpois/io/s3.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,25 @@ def upload_partitioned_dataset(
4343
)
4444

4545
return len(parquet_files)
46+
47+
48+
def upload_single_file(
49+
local_path: Path,
50+
bucket: str,
51+
s3_key: str,
52+
s3_region: str,
53+
content_type: str = "application/octet-stream",
54+
) -> str:
55+
"""Upload a single local file to S3.
56+
57+
Returns the public HTTPS URL of the uploaded object.
58+
"""
59+
s3 = boto3.client("s3", region_name = s3_region)
60+
print(f"Uploading {local_path.name} to s3://{bucket}/{s3_key} ...")
61+
s3.upload_file(
62+
Filename = str(local_path),
63+
Bucket = bucket,
64+
Key = s3_key,
65+
ExtraArgs = {"ContentType": content_type},
66+
)
67+
return f"https://{bucket}.s3.{s3_region}.amazonaws.com/{s3_key}"

0 commit comments

Comments
 (0)