forked from dianephan/flask-aws-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3_functions.py
33 lines (29 loc) · 1.1 KB
/
s3_functions.py
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
29
30
31
32
33
import boto3
def upload_file(file_name, bucket):
object_name = file_name
s3_client = boto3.client('s3')
response = s3_client.upload_file(file_name, bucket, object_name)
return response
def list_files(bucket):
s3_client = boto3.client('s3')
contents = []
try:
for item in s3_client.list_objects(Bucket=bucket)['Contents']:
# print(item)
contents.append(item)
except Exception as e:
pass
return contents
def show_image(bucket):
s3_client = boto3.client('s3')
# location = boto3.client('s3').get_bucket_location(Bucket=bucket)['LocationConstraint']
public_urls = []
try:
for item in s3_client.list_objects(Bucket=bucket)['Contents']:
presigned_url = s3_client.generate_presigned_url('get_object', Params = {'Bucket': bucket, 'Key': item['Key']}, ExpiresIn = 100)
# print("[DATA] : presigned url = ", presigned_url)
public_urls.append(presigned_url)
except Exception as e:
pass
# print("[DATA] : The contents inside show_image = ", public_urls)
return public_urls