Skip to content

Commit

Permalink
Support video uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesoff committed Feb 15, 2018
1 parent 9334824 commit 11a6770
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lambda/lambda_function.py
Expand Up @@ -2,6 +2,7 @@
import pystache
import urllib
import os
import os.path

from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch_all
Expand All @@ -14,6 +15,15 @@ def lambda_handler(event, context):
bucket = record['s3']['bucket']['name']
key = urllib.unquote_plus(record['s3']['object']['key'])
key_filename = key.split('/')[1]

is_image = True
is_video = False
(_, key_extension) = os.path.splitext(key_filename)
key_extension = key_extension.lower()
if key_extension.lower() in ['.mp4']:
is_image = False
is_video = True

print('Downloading template')
template_body_response = s3.get_object(
Bucket=bucket,
Expand All @@ -23,7 +33,7 @@ def lambda_handler(event, context):
target_filename = record['s3']['object']['eTag'][0:8]
target_object = 'v/{}'.format(target_filename)
labels = []
if CLOUD_BUCKET_REGION is not None:
if is_image and CLOUD_BUCKET_REGION is not None:
try:
response = rekognition.detect_labels(Image={'S3Object': {
'Bucket': bucket,
Expand All @@ -50,7 +60,9 @@ def lambda_handler(event, context):
'target_object': target_object,
'twitter': CLOUD_TWITTER,
'has_twitter': CLOUD_TWITTER is not None,
'description': description
'description': description,
'is_image': is_image,
'is_video': is_video
}))
xray_recorder.end_subsegment()
print('Writing rendered template to {}'.format(target_object))
Expand Down
5 changes: 5 additions & 0 deletions s3-files/inc/style.css
Expand Up @@ -14,3 +14,8 @@ body {
box-shadow: 0px 0px 5px 6px #101010;
}

#asset_video {
max-width: 95vw;
max-height: 95vh;
box-shadow: 0px 0px 5px 6px #101010;
}
8 changes: 8 additions & 0 deletions s3-files/template/template.html
Expand Up @@ -20,7 +20,15 @@
<body>

<div id="container">
{{#is_image}}
<img src="/{{url}}" id="asset" alt="{{description}}" onClick="toggle()" />
{{/is_image}}
{{#is_video}}
<video controls id="asset_video">
<source src="/{{url}}" type="video/mp4">
No video support (or not enough) in browser.
</video>
{{/is_video}}
</div>

<script src="/inc/resize.js" type="application/javascript"></script>
Expand Down

0 comments on commit 11a6770

Please sign in to comment.