This commit is contained in:
caramelteawithmint
2026-11-13 18:18:57 +03:00
parent 09e26c3c5a
commit a72f814e65
8 changed files with 574 additions and 62 deletions
+40 -1
View File
@@ -1,7 +1,38 @@
# 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"]
import boto3
from botocore.config import Config
from .config import get_settings
def get_s3_client():
s = get_settings()
return boto3.client(
@@ -13,6 +44,7 @@ def get_s3_client():
config=Config(signature_version="s3v4"),
)
def upload_fileobj(fileobj, key: str, content_type: str):
client = get_s3_client()
s = get_settings()
@@ -23,8 +55,15 @@ def upload_fileobj(fileobj, key: str, content_type: str):
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"]
return obj["Body"]
def delete_file(key: str):
client = get_s3_client()
s = get_settings()
client.delete_object(Bucket=s.s3_bucket, Key=key)