Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

silverlogic/django-cloudflare-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[DEPRECATED] Django Cloudflare Stream Field.

This code has been moved to https://github.com/silverlogic/baseapp-backend/tree/master/baseapp-cloudflare-stream-field

This app provides integration with Cloudflare Stream, where you can upload directly to Cloudflare using TUS protocol.

Install the package

Add to requirements/base.txt:

django-cloudflare-stream @ git+https://github.com/silverlogic/django-cloudflare-stream.git

Add the following to your settings/base.py:

# Cloudflare
CLOUDFLARE_ACCOUNT_ID = env("CLOUDFLARE_ACCOUNT_ID")
CLOUDFLARE_API_TOKEN = env("CLOUDFLARE_API_TOKEN")
CLOUDFLARE_AUTH_EMAIL = env("CLOUDFLARE_AUTH_EMAIL")

# Make sure to add the task routing for refresh_from_cloudflare and generate_download_url
CELERY_TASK_ROUTES = {
    "cloudflare_stream_field.tasks.refresh_from_cloudflare": {
        "exchange": "default",
        "routing_key": "default",
    },
    "cloudflare_stream_field.tasks.generate_download_url": {
        "exchange": "default",
        "routing_key": "default",
    },
}

Include the URLs in your main urls.py file:

re_path(r"^cloudflare-stream-upload/", include("cloudflare_stream_field.urls")),

And if you use Django REST Framework, add the following to your router:

# Cloudflare Stream Upload
from cloudflare_stream_field.rest_framework import CloudflareStreamUploadViewSet

router.register(
    r"cloudflare-stream-upload", CloudflareStreamUploadViewSet, basename="cloudflare-stream-upload"
)

Register App

INSTALLED_APPS = [
    # ----
    'cloudflare_stream_field',
]

Allow CORS Headers

You need to add tus-resumable, upload-length, upload-metadata, upload-creator to your CORS header. Add the following to settings/base.py:

CORS_ALLOW_HEADERS = [
    "accept",
    "accept-encoding",
    "authorization",
    "content-type",
    "dnt",
    "origin",
    "user-agent",
    "x-csrftoken",
    "x-requested-with",
    "tus-resumable",
    "upload-length",
    "upload-metadata",
    "upload-creator"
]

Usage

Import and use the field in your models file:

from cloudflare_stream_field import CloudflareStreamField

class Post(models.Model):
    video = CloudflareStreamField(null=True, blank=True, downloadable=False)

If you set downloadable to True it will automatically trigger a task to generate and save the download url at obj.video['meta']['download_url'].

CloudflareStreamField inherits from JSONField so you can use any look it provides, like filter only for videos fully processed by Cloudflare:

Post.objects.filter(video__status__state="ready")

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published