-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathS3Bucket.py
37 lines (26 loc) · 986 Bytes
/
S3Bucket.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
34
35
import boto3
class S3Bucket:
BUCKET_NAME = 'snapshot-dev-s3bucket'
BUCKET_URL = "https://s3-us-west-1.amazonaws.com/" + BUCKET_NAME
AWS_ID = 'AKIAJHIKEBDCJEEA4W6Q'
AWS_KEY = 'AYQCTb8HeFTxZ1SKYbI3h6mp34CWhPos9kIsS+GV'
s3 = boto3.resource('s3', aws_access_key_id=AWS_ID, aws_secret_access_key=AWS_KEY)
@classmethod
def add(cls, localPath, fileKey):
file = cls.s3.Object(cls.BUCKET_NAME, fileKey)
file.put(ACL='public-read', Body=open(localPath,'rb'))
@classmethod
def getUrl(cls, fileKey):
urlKey = fileKey.replace(" ", "+")
return cls.BUCKET_URL + "/" + urlKey
@classmethod
def delete(cls,fileKey):
cls.s3.Object(cls.BUCKET_NAME, fileKey).delete()
# # Examples:
# S3Bucket.add('../f 1.pdf', 'file 1.pdf')
# S3Bucket.delete("org/InteractionMaterial/20121212/cultural 1.docx")
#
#
# for bucket in S3Bucket.s3.buckets.all():
# for object in bucket.objects.all():
# print(object.key)