Django video upload

Django video upload overview

As with images, Cloudinary’s video management solution enables you to upload videos to the cloud and perform manipulations. Cloudinary’s RESTful API and the Django client library (SDK) allow you to upload videos from server-side code, directly from the browser, or from a mobile app. You can transcode your videos to all relevant formats, apply a wide range of video transformations, and stream your optimized videos via CDN to web browsers and mobile devices.

The upload process for videos is generally the same as that for images, and you can apply essentially all image upload functionality to video as well. For details, see the Django image upload documentation.

This section provides an overview and examples of video upload functionality using Python and Django.

For complete details on all video upload functionality, see Upload videos.
For the complete list of available upload parameters, see the Upload method of the Upload API Reference.

Django video upload functionality

The Django/Python (pycloudinary) SDK package wraps the Cloudinary upload API to help you upload your videos to the cloud via server upload or as a direct upload from the browser or your mobile app. Direct upload of video from the browser works the same way as direct image upload. It requires the JQuery upload plugin and some configuration setup. For details, see Direct uploading from the browser.

You can also use the upload widget for uploads of user-generated video content.

Although most video transformations can be performed on-the-fly and the resulting video can stream even while the derived video is being generated, it can sometimes be a good idea to perform your transformations eagerly as part of the upload. This is especially true for longer videos, so that the final video is ready for fast delivery when the first user requests it.

For user-generated video content, consider utilizing incoming transformations and upload presets.

To avoid the risks of network issues, you can take advantage of the upload_large method, which uploads large videos to the cloud in chunks.

You can also integrate your video upload with Django models and forms using the relevant helper classes. For details, see Integration with Django forms and models.

Django video upload examples

This section provides examples of some of the Django video upload features mentioned in the previous section.

Example 1: Server-side upload

The following example uploads dog.mp4 to Cloudinary and stores it in a bi-level folder structure with the public ID dog_closeup. It also performs two eager transformations that resize the video to a square and a small rectangle.

cloudinary.uploader.upload("dog.mp4", resource_type = "video",
            public_id = "my_folder/my_sub_folder/dog_closeup",
            eager = [
              {"width": 300, "height": 300,
                  "crop": "pad", "audio_codec": "none"},
              {"width": 160, "height": 100,
                  "crop": "crop", "gravity": "south",
                  "audio_codec": "none"}],
            eager_async = true,
            eager_notification_url = "http://mysite/notify_endpoint")

Example 2: Client-side upload from the browser (signed upload)

The following example renders a direct file upload input field using the CloudinaryJsFileField helper method. Although the default resource_type for this method is auto, the video type is explicitly defined, and asynchronous eager transformations are used to generate adaptive bitrate streaming content. The html parameter is used to include standard HTML parameters (in this case, an id attribute) in the generated tag.

Note: This example assumes you have already included and configured the JQuery files as described in Direct uploading from the browser.

CloudinaryJsFileField(attrs = { 'id':'my_upload_tag'},
    options= {
        'resource_type': 'video',
        'eager' : [{'streaming_profile' : "full_hd", 'format': "m3u8"}], 
        'eager_async': 'true', 
        'eager_notification_url' : "http://mysite/notify_endpoint"})

Example 3: Client-side upload from the browser (unsigned upload)

The following example renders a an unsigned direct file upload input field using the CloudinaryUnsignedJsFileField helper method. The default resource_type for this method is auto, so it can be used for images, video, and raw files. The method defines a public_ID and tags for the uploaded file.

Note: This example assumes you have already included and configured the JQuery files as described in Direct uploading from the browser. It also assumes that my_upload_preset is defined as an unsigned preset for your account.

CloudinaryUnsignedJsFileField(upload_preset='my_upload_preset', 
    options={
        'public_id':'my_video', 
        'tags':["user_218","screencast"]})