Commit de448400 authored by Ilya Simonov's avatar Ilya Simonov

Revert "test do s3 storage"

This reverts commit 202366e1.
parent 202366e1
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -100,7 +100,7 @@ class Video(BaseModel):
description = models.TextField(_('description'), blank=True, null=True)
local_file = models.FileField(
_('local file'),
storage=S3Boto3Storage(bucket_name='cp-video-files'),
upload_to=asset_upload,
blank=True,
null=True,
)
......
......@@ -6,13 +6,13 @@ from django.conf import settings
def upload_file(content, key, content_type):
s3 = boto3.client(
's3',
aws_access_key_id=settings.FINAL_AWS_ACCESS_KEY_ID,
aws_secret_access_key=settings.FINAL_AWS_SECRET_ACCESS_KEY,
region_name=settings.FINAL_AWS_REGION_NAME
aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
region_name=settings.AWS_REGION_NAME
)
s3.put_object(
Bucket=settings.FINAL_AWS_STORAGE_BUCKET_NAME,
Bucket=settings.AWS_STORAGE_BUCKET_NAME,
Key=key,
Body=content,
ContentType=content_type,
......
......@@ -7,18 +7,18 @@ from django.db.models.signals import post_save
from . import models, utils, s3_uploader
# @receiver(post_save, sender=models.Video)
# def generate_default_thumbnail_for_video(sender, instance, **kwargs):
# if not instance.thumbnail and instance.local_file:
# if os.path.isfile(instance.local_file.path):
# thumbnail_name = utils.generate_thumbnail(instance.local_file)
# key = f'videos/{thumbnail_name}'
# thumbnail_path = f'{settings.MEDIA_ROOT}{key}'
#
# content = utils.get_thumbnail_content(thumbnail_path)
# content_type = 'image/jpeg'
# instance.thumbnail = s3_uploader.upload_file(content, key, content_type)
#
# instance.save(update_fields=['thumbnail'])
#
# os.remove(thumbnail_path)
@receiver(post_save, sender=models.Video)
def generate_default_thumbnail_for_video(sender, instance, **kwargs):
if not instance.thumbnail and instance.local_file:
if os.path.isfile(instance.local_file.path):
thumbnail_name = utils.generate_thumbnail(instance.local_file)
key = f'videos/{thumbnail_name}'
thumbnail_path = f'{settings.MEDIA_ROOT}{key}'
content = utils.get_thumbnail_content(thumbnail_path)
content_type = 'image/jpeg'
instance.thumbnail = s3_uploader.upload_file(content, key, content_type)
instance.save(update_fields=['thumbnail'])
os.remove(thumbnail_path)
......@@ -13,15 +13,13 @@ def send_video_to_s3():
for local_video in local_videos:
video_name = local_video.local_file.name.split('/')[-1]
print('video_name', video_name)
key = asset_upload(local_video, video_name)
print('key', key)
content = local_video.local_file.read()
local_video.s3_file = upload_file(content, key, 'video/mp4')
local_video.status = READY
local_video.save(update_fields=['s3_file', 'status'])
# os.remove(local_video.local_file.path)
os.remove(local_video.local_file.path)
local_videos.update(local_file=None)
......@@ -160,19 +160,9 @@ path = f'{BASE_DIR}/cp_video/local.py'
if os.path.exists(path):
from .local import *
else:
FINAL_AWS_STORAGE_BUCKET_NAME = env('AWS_STORAGE_BUCKET_NAME')
FINAL_AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID')
FINAL_AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY')
FINAL_AWS_REGION_NAME = env('AWS_REGION_NAME')
AWS_STORAGE_BUCKET_NAME = env('AWS_STORAGE_BUCKET_NAME')
AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY')
AWS_REGION_NAME = env('AWS_REGION_NAME')
# CloudFront
FINAL_AWS_S3_CUSTOM_DOMAIN = env('AWS_S3_CUSTOM_DOMAIN')
AWS_ACCESS_KEY_ID = 'DO00FPURLTXA34ZCTVP7'
AWS_SECRET_ACCESS_KEY = '0gnDLjAoAF+rbKgDVWEln5K7rdPXDxq2/E7C8k3q7IU'
AWS_STORAGE_BUCKET_NAME = 'cp-video-files'
AWS_S3_ENDPOINT_URL = 'https://cp-video-files.nyc3.digitaloceanspaces.com'
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
AWS_LOCATION = 'media'
AWS_DEFAULT_ACL = 'public-read'
AWS_S3_CUSTOM_DOMAIN = env('AWS_S3_CUSTOM_DOMAIN')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment