4_grade
This commit is contained in:
+40
-1
@@ -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)
|
||||
Reference in New Issue
Block a user