Cloudinary Blog

Video Uploads With Cloudinary

Video Uploads With Cloudinary

Setting up the infrastructure for video uploads can go from straightforward to complex real fast. Why? Because many challenges are involved in building a foolproof service for an efficient and smooth process.

Platform Test for Video Uploads

Just as Stack Overflow cofounder Joel Spolsky did when he wrote the Joel Test for writing better software over two decades ago, I’ll share with you the seven questions that need robust answers for efficient video uploads on a web or mobile platform:

  1. Can your video upload platform accept multiple video uploads at the same time?
  2. Can your video upload platform gracefully restrict the size and formats of user-generated uploads?
  3. Can your video upload platform crop, manipulate, and transform video uploads on the fly before storage?
  4. Can your video upload platform chunk videos, especially large ones, during upload?
  5. Can your video upload platform compress and optimize videos on or after upload, e.g., optimize a 50-MB video to one that weighs 15 MB only without any noticeable quality changes?
  6. Can your video upload platform convert videos from one encoding format to another, e.g., from .mov to .mp4?
  7. Can your video upload platform store and accept as many videos as possible while your audience exponentially grows? For example, the storage capacity of YouTube is, incredibly, around 1 exabyte (1 trillion GB). Even if your platform is not on this scale, it should at least be scalable to approximately 1 petabyte (1 million GB).

Cloudinary as a media-management service offers numerous capabilities, including video uploads, and can answer the above questions with a resounding yes. As you ponder on those questions, I’ll show you the four ways in which you can upload videos with Cloudinary.

Video Uploads With the Upload Widget

Every app has a user interface called the front end. A snappy and intuitive interface is a must for video uploads. Cloudinary offers a slick, easy-to-use upload widget you can integrate into your app with only a few lines of code.

Cloudinary Upload Widget

Cloudinary Upload Widget

To quickly set up the upload widget:

Copy to clipboard
<button id="upload_widget" class="cloudinary-button">Upload Video Files</button>

<script src="https://widget.cloudinary.com/v2.0/global/all.js" type="text/javascript"></script>  

<script type="text/javascript">  
var myWidget = cloudinary.createUploadWidget({
  cloudName: 'my_cloud_name', 
  uploadPreset: 'my_preset'}, (error, result) => { 
    if (!error && result && result.event === "success") { 
      console.log('Done! Here is the image info: ', result.info); 
    }
  }
)

document.getElementById("upload_widget").addEventListener("click", function(){
    myWidget.open();
  }, false);
</script>

The upload widget supports the following out of the box:

Upload Widget

  • Multiple third-party sources, i.e., you can upload videos from Google Drive, Dropbox, Facebook, Instagram, or a web address with the widget.
  • Multiple video uploads that run concurrently.
  • On-the-fly tagging of videos.
  • Skin customization of the widget to fit the theme of your app.
  • Localization to accommodate non-English-speaking users.

Video Uploads With the Upload API

Cloudinary’s REST API for uploads can perform all the tasks of the upload widget and many others with an extensive set of features for uploads, manipulation, transformation, and delivery.

With a direct call to the API’s URL through an HTTPS POST request, your app can upload videos directly to Cloudinary. For example:

URL: https://api.cloudinary.com/v1_1/<cloud name>/<resource_type>/upload cloud_name refers to your account’s cloud name, which is shown on your console. resource_type refers to the type of file to upload. You can specify a value, such as image, raw, video, or auto to have Cloudinary automatically detect the file type. However, you don’t have to manually make direct HTTP calls. Cloudinary offers SDKs for PHP, Node.js, Ruby, Go, .NET, iOS, Android, Kotlin, and other popular frameworks, such as Laravel, Django, and Rails, complete with fluent and expressive methods.

Ruby:
Copy to clipboard
cl_video_tag("dog", :quality=>"auto", :fetch_format=>:auto)
PHP v1:
Copy to clipboard
cl_video_tag("dog", array("quality"=>"auto", "fetch_format"=>"auto"))
PHP v2:
Copy to clipboard
(new VideoTag('dog'))
  ->delivery(Delivery::format(Format::auto()))
  ->delivery(Delivery::quality(Quality::auto()));
Python:
Copy to clipboard
CloudinaryVideo("dog").video(quality="auto", fetch_format="auto")
Node.js:
Copy to clipboard
cloudinary.video("dog", {quality: "auto", fetch_format: "auto"})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().quality("auto").fetchFormat("auto")).videoTag("dog");
JS:
Copy to clipboard
cloudinary.videoTag('dog', {quality: "auto", fetchFormat: "auto"}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.video("dog", {quality: "auto", fetch_format: "auto"})
React:
Copy to clipboard
<Video publicId="dog" >
  <Transformation quality="auto" fetchFormat="auto" />
</Video>
Vue.js:
Copy to clipboard
<cld-video publicId="dog" >
  <cld-transformation quality="auto" fetchFormat="auto" />
</cld-video>
Angular:
Copy to clipboard
<cl-video public-id="dog" >
  <cl-transformation quality="auto" fetch-format="auto">
  </cl-transformation>
</cl-video>
.NET:
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation().Quality("auto").FetchFormat("auto")).BuildVideoTag("dog")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().quality("auto").fetchFormat("auto")).resourceType("video").generate("dog.mp4");
iOS:
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation().setQuality("auto").setFetchFormat("auto")).generate("dog.mp4")

Video Uploads With the Media Library UI

Uploading videos through the Cloudinary Media Library UI is the simplest and most straightforward way. No setup or integration is required. All you need to do is log in to your Cloudinary account, click the Media Library tab on the Cloudinary dashboard, and drag and drop videos to the library.

media library

Alternatively, click the Upload button on the upper-right corner to invoke the widget for uploads.

upload

Video Uploads With the Media Library UI Widget

With its features for rich search and optimized media-asset delivery, Cloudinary’s Media Library UI widget gives you all the capabilities of the Media Library UI. You can Integrate that widget into any CMS or web app with only a few lines of code. Afterwards, all users can access videos directly from your Cloudinary account and use them as they wish in the app.

Tip
Try out some of the configuration options in this Media Library interactive demo. Although it does not cover every possible option, the demo generates the code required for implementing the options you select, making for an ideal sandbox for getting started with the widget. For a personalized experience, specify your cloud name and API key. (To obtain those two credentials, sign up for a free account).

ML demo

The following code performs the integration:

Copy to clipboard
<button id="open-btn" class="open-btn">Upload Video Files</button>

<script src="https://media-library.cloudinary.com/global/all.js" type=text/javascript></script>

<script type="text/javascript">  
    window.ml = cloudinary.createMediaLibrary({
   cloud_name: 'xxxxx',
   api_key: 'xxxxx',
   username: 'xxxxx',
   button_class: 'myBtn',
   button_caption: 'Select Video',
 }, {
     insertHandler: function (data) {
       data.assets.forEach(asset => { console.log("Inserted asset:",
       JSON.stringify(asset, null, 2)) })
       }
    },
    document.getElementById("open-btn")
)
</script>

For more details on integrating the Cloudinary Media Library UI widget, check out this comprehensive guide.

Next Steps

Video upload is only one of the many functions of the entire spectrum of Cloudinary’s media-management pipeline. Cloudinary also transforms, optimizes, and delivers videos. Transformations can occur just before or after upload, or on the fly. For details, see the related documentation.

In addition, Cloudinary’s JavaScript-based HTML5 video player delivers uploaded videos in an optimal way. Besides being bundled with many valuable customization and integration capabilities, the video player is monetization and analytics ready, fully responsive for use in any device or screen size, and is integrated with Cloudinary's video-delivery and manipulation capabilities.

Copy to clipboard
<div style="max-width: px">
    <video id="doc-player" controls muted class="cld-video-player cld-fluid"></video>
</div>
Copy to clipboard
var cld = cloudinary.Cloudinary.new({ cloud_name: 'demo' });
var demoplayer = cld.videoPlayer('doc-player').width(600);
demoplayer.source('race_road_car')

To further explore the video player, see the related documentation.

Recent Blog Posts

Auto-Tag Videos With Cloudinary: A Tutorial

Video is one of the best ways for capturing audience attention. Product demonstrations, property tours, tutorials, and keynotes all make great content—provided that they’re readily searchable by your team and visitors alike. Even though tagging and categorization help organize videos and make them easy to find, the labeling process is labor intensive, taking time away from key tasks like creating new videos.

Read more
Optimize Media to Get Ready for Google’s Core Web Vitals

For years, Google has been updating its search algorithm to prioritize end-user experience, displaying the most relevant and helpful content at the top of search results. The latest—and maybe the most significant—update so far is Core Web Vitals (CWVs), which are new metrics announced a year ago that will, starting in June, begin determining search rankings. With this update, Google is being abundantly clear that visual experience of webpages is paramount.

Read more
Compressing, Resizing, and Optimizing Videos in Laravel

Videos are large media files—in most cases, at least four times larger than images—and are often created for ads, marketing campaigns, and instructional content to convey as much information as possible in a short time. Ensuring that videos do not buffer all the time and that the user’s data is protected from rapid consumption due to heavy page weight must be the modus operandi for all website builders and e-business owners.

Read more
Five Ways to Effectively Manage Online Media

The digital economy is driven by highly visual experiences. After all, viewers process images 60,000 times faster than text. Therefore, it’s no surprise that top-notch visual media has been an essential component of a captivating e-commerce experience for years. Nor is it surprising that visual media’s importance only rose during the COVID-19 pandemic, a reality for all retailers, including our client Levi’s.

Read more
Creating an API With Python Flask to Upload Files to Cloudinary

Code

Cloudinary offers SDKs for many programming languages and frameworks. Even though it also offers an Upload API endpoint for both back-end and front-end code, most developers find the SDKs very helpful. If you're working with a powerful back-end framework like Python Flask, you'll be happy to hear that a Python SDK is now available.
This tutorial walks you through the process of building an API to upload images to Cloudinary. You can also upload other file types, including video and even nonmedia files, with the API.

Read more
How to Use the Cloudinary Media Editor Widget

At Cloudinary, we manage the entire pipeline of media assets for thousands of customers of varying sizes from numerous verticals.

As part of our commitment to support the entire flow of media assets, we are now introducing an intuitive media editing widget: an out­-of­-the-­box, interactive UI providing your users with a set of common image editing actions for immediate use on your website or web app. The widget is interactive and simple, built on Cloudinary's transformation capabilities, and requiring only a few lines of code to integrate. Afterwards, you can seamlessly and effortlessly add content to your site or app with no need for in-house image editing capabilities.

Read more