def create_post_media_video(cls, file, post_id, order): hash = sha256sum(file=file.file) video_backend = get_backend() if isinstance(file, InMemoryUploadedFile): # If its in memory, doing read shouldn't be an issue as the file should be small. in_disk_file = write_in_memory_file_to_disk(file) thumbnail_path = video_backend.get_thumbnail( video_path=in_disk_file.name, at_time=0.0) else: thumbnail_path = video_backend.get_thumbnail( video_path=file.file.name, at_time=0.0) with open(thumbnail_path, 'rb+') as thumbnail_file: post_video = cls.objects.create( file=file, post_id=post_id, hash=hash, thumbnail=File(thumbnail_file), ) PostMedia.create_post_media(type=PostMedia.MEDIA_TYPE_VIDEO, content_object=post_video, post_id=post_id, order=order) return post_video
def create_post_media_image(cls, image, post_id, order): hash = sha256sum(file=image.file) post_image = cls.objects.create(image=image, post_id=post_id, hash=hash, thumbnail=image) PostMedia.create_post_media(type=PostMedia.MEDIA_TYPE_IMAGE, content_object=post_image, post_id=post_id, order=order) return post_image
def create_post_video(cls, video, post_id): hash = sha256sum(file=video.file) return cls.objects.create(video=video, post_id=post_id, hash=hash)
def create_post_image(cls, image, post_id): hash = sha256sum(file=image.file) return cls.objects.create(image=image, post_id=post_id, hash=hash)