-
Notifications
You must be signed in to change notification settings - Fork 7
/
upload2aws.py
55 lines (41 loc) · 1.57 KB
/
upload2aws.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python
# this source is part of my Hackster.io project: https://www.hackster.io/mariocannistra/radio-astronomy-with-rtl-sdr-raspberrypi-and-amazon-aws-iot-45b617
# use this program to test the AWS S3 connection using the test-chart.png file
import boto
from boto.s3.key import Key
import boto.s3.connection
import radioConfig
import sys
from datetime import datetime
import ntpath
def push_picture_to_s3(id):
# id should have the folder name as YYYYMMDD/filename.ext
BUCKET_NAME = 'jupiter-spectrograms'
AWS_ACCESS_KEY_ID = radioConfig.AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY = radioConfig.AWS_SECRET_ACCESS_KEY
# connect to the bucket
conn = boto.s3.connect_to_region('eu-central-1',
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
is_secure=True, # uncommmnt if you are not using ssl
calling_format = boto.s3.connection.OrdinaryCallingFormat(),
)
#print(conn)
keyname = '%s/%s' % ( radioConfig.scanTarget, id )
#print(keyname)
#fn = '%s.png' % id
fn = id
#print(fn)
bucket = conn.get_bucket(BUCKET_NAME)
#print(bucket)
#print "uploading file"
key = bucket.new_key(keyname)
key.set_contents_from_filename(fn)
print(' file uploaded to aws s3')
print(" setting acl to public read")
key.set_acl('public-read')
# we need to make it public so it can be accessed publicly
# using a URL like http://s3.amazonaws.com/bucket_name/key
print(" making key public")
key.make_public()
push_picture_to_s3(sys.argv[1])