File size: 698 Bytes
3d98680
 
 
 
 
 
 
 
 
 
25d2247
3d98680
 
 
 
 
 
 
 
 
25d2247
3d98680
 
 
 
 
 
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 streamlit as st
import uuid
import boto3

s3 = boto3.client(
    's3',
    aws_access_key_id=st.secrets["AWS_ACCESS_KEY"],
    aws_secret_access_key=st.secrets["AWS_SECRET_KEY"]
)

def upload_file(data, bucket=st.secrets["S3_BUCKET"]):
    file_name = uuid.uuid4().hex
    try:
        key = f"{file_name}.pkl"
        response = s3.put_object(Body=data, Bucket=bucket, Key=key)
    except Exception as e:
        return None
    return file_name


def get_file(file_name, bucket=st.secrets["S3_BUCKET"]):
    try:
        response = s3.get_object(Bucket=bucket, Key=f"{file_name}.pkl")
        return response['Body'].read()
    except Exception as e:
        print(e)
        return False