-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage2url.py
More file actions
25 lines (21 loc) · 754 Bytes
/
image2url.py
File metadata and controls
25 lines (21 loc) · 754 Bytes
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
import boto3
import os, json
def get_s3_resource():
with open('secrets.json', 'r') as file:
data = json.load(file)
access_key_id = data['aws_access_key_id']
secret_key = data['aws_secret_access_key']
return boto3.resource(
service_name='s3',
region_name='ap-south-1',
aws_access_key_id=access_key_id,
aws_secret_access_key=secret_key
)
def image2url(file_path, object_name=None):
bucket_name = 'eyes-of-tryon'
if object_name is None:
object_name = file_path
s3 = get_s3_resource()
s3.Bucket(bucket_name).upload_file(Filename=file_path, Key=object_name)
public_url = f"https://{bucket_name}.s3.ap-south-1.amazonaws.com/{object_name}"
return public_url