File size: 728 Bytes
ceefdfd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os

import boto3
from dotenv import load_dotenv

load_dotenv()


def upload_to_s3(file_path, file_name):
    ACCESS_KEY = os.getenv("AWS_ACCESS_KEY")
    SECRET_KEY = os.getenv("AWS_SECRET_KEY")

    try:
        # Initialize a session using DigitalOcean Spaces.
        session = boto3.session.Session()
        client = session.client(
            "s3",
            region_name="ams3",
            endpoint_url="https://ams3.digitaloceanspaces.com",
            aws_access_key_id=ACCESS_KEY,
            aws_secret_access_key=SECRET_KEY,
        )

        client.upload_file(Filename=file_path, Key=f"{file_name}", Bucket="adina-poc")

    except Exception as e:
        print("Error uploading file to S3 bucket.", e)