lab3_and_3grade

This commit is contained in:
caramelteawithmint
2026-11-13 18:01:54 +03:00
parent ec540a1a72
commit 09e26c3c5a
28 changed files with 1494 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
import boto3
from botocore.config import Config
from .config import get_settings
def get_s3_client():
s = get_settings()
return boto3.client(
"s3",
endpoint_url=s.s3_endpoint,
aws_access_key_id=s.s3_access_key,
aws_secret_access_key=s.s3_secret_key,
region_name=s.s3_region,
config=Config(signature_version="s3v4"),
)
def upload_fileobj(fileobj, key: str, content_type: str):
client = get_s3_client()
s = get_settings()
client.upload_fileobj(
fileobj,
s.s3_bucket,
key,
ExtraArgs={"ContentType": content_type},
)
def download_fileobj(key: str):
client = get_s3_client()
s = get_settings()
obj = client.get_object(Bucket=s.s3_bucket, Key=key)
return obj["Body"]