lavkach3
1import logging
2import os
3
4import boto3
5from botocore.exceptions import ClientError
6
7from core.db_config import config
8
9
10class S3:
11def __init__(self):
12self.bucket = config.AWS_DEFAULT_BUCKET
13self.s3_client = boto3.client(
14service_name='s3',
15region_name=config.AWS_DEFAULT_REGION,
16endpoint_url='https://storage.yandexcloud.net',
17aws_access_key_id=config.AWS_ACCESS_KEY_ID,
18aws_secret_access_key=config.AWS_SECRET_ACCESS_KEY,
19)
20
21async def upload_file(self, file_name, object_name=None):
22if object_name is None:
23object_name = os.path.basename(file_name)
24# Upload the file
25try:
26self.s3_client.upload_file(file_name, self.bucket, object_name)
27except ClientError as e:
28logging.error(e)
29return False
30return True
31
32
33s3_client = S3()
34