lab3_and_3grade
This commit is contained in:
@@ -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"]
|
||||
Reference in New Issue
Block a user