-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3.py
26 lines (20 loc) · 761 Bytes
/
s3.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
import boto3
import cv2
import tempfile
from log import log
def upload_image(frame, s3_key):
# write frame to temporary file
file = tempfile.NamedTemporaryFile(suffix='.jpg', delete=True)
log.debug(f'writing to temp {file.name}')
write_success = cv2.imwrite(file.name, frame)
if not write_success:
log.error(f'couldnt save image to {file.name}')
# Create an S3 client
s3 = boto3.client('s3')
# Uploads the given file using a managed uploader, which will split up large
# files automatically and upload parts in parallel.
BUCKET_NAME = 'slow-down-speed-cam'
log.info(f'uploading to s3 {BUCKET_NAME}')
s3.upload_file(file.name, BUCKET_NAME, s3_key)
log.debug(f'upload complete')
return s3_key