def upload_to_s3(key): temp_vid_slug = key + '_tmp' if os.path.isdir(settings.LIVE_VIDEOS_PATH): send_to_s3(temp_vid_slug, os.path.join(settings.LIVE_VIDEOS_PATH, choice(video_list))) else: send_to_s3(temp_vid_slug, settings.FILE_LOCATION) enqueue(temp_vid_slug)
def handle_uploaded_file(video, slug): """ Handler for uploaded video via the java recorder. Sends the video to s3 and queues it for encoding on the ec2 nodes. """ try: connection = pika.BlockingConnection( pika.ConnectionParameters(settings.RABBITMQ_SERVER)) except: logger.exception('connection problem') raise forms.ValidationError( "We are experiencing a connection problem " "and cannot perform uploads for now. Please try again later.") filename = os.path.join(settings.MEDIA_ROOT, 'tmp/%s.mp4' % slug) logger.debug('Opening file %s' % filename) tmp_file = open(filename, 'wb+') logger.debug('file opened') tmp_slug = "%s_tmp" % slug for chunk in video.chunks(): tmp_file.write(chunk) tmp_file.close() logger.debug('sending to s3') if settings.PUSH_TO_S3: send_to_s3(tmp_slug, filename) logger.debug('done sending') logger.debug('enqueuing file') enqueue(tmp_slug) logger.debug('done enqueue') logger.debug('removing file') # Remove the file from the server after being uploaded to s3 and # queued for encoding if settings.PUSH_TO_S3: os.remove(filename) logger.debug('done removing')