Skip to content

Commit 4bb9903

Browse files
author
Miguel Wychovaniec
committed
Added S3_File_Upload project, as requestes on issue Python-World#449
1 parent f4bb6a2 commit 4bb9903

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

projects/S3_File_Upload/main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import boto3
2+
from botocore.exceptions import NoCredentialsError
3+
4+
ACCESS_KEY = 'XXXXXXXXXXXXXXXXX'
5+
SECRET_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
6+
7+
def upload_to_s3(local_file, bucket, s3_file):
8+
s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,
9+
aws_secret_access_key=SECRET_KEY)
10+
try:
11+
s3.upload_file(local_file, bucket, s3_file)
12+
print("Upload Successful")
13+
return True
14+
except FileNotFoundError:
15+
print("The file was not found")
16+
return False
17+
except NoCredentialsError:
18+
print("Credentials not available")
19+
return False
20+
21+
22+
result = upload_to_s3('local_file_name', 'bucket_name', 'file_name_on_s3')

0 commit comments

Comments
 (0)