User Generated Content in Brightcove 3

Written by Bob de Wit. Posted in Brightcove, Developer Blog, Flex

User generated content (UGC, often hyphenated), also known as Consumer Generated Media (CGM) or User created Content (UCC), refers to various kinds of media content, publicly available, that are produced by end-users. In the Brightcove universe, this of course refers to videos created and contributed by site users. As your end-users typically do not have access to your Brightcove Studio administration console, UGC needs to be fed into Brightcove in another way. Several methods exist, depending on the release you are using. This article focuses on the possibilities of BC3. There are two main approaches to integrating UGC:
  • Direct upload from the user’s computer to Brightcove using Flash, Flex, JavaScript or Desktop Applications and the Media API.
  • Indirect upload to an intermediate server using any combination of client & server development languages. From the intermediate server the feed can be sent through Media API calls or using FTP.
The second option is recommended for a plethora of reasons. Mainly, it is a question of security: a client-side script talking to the Media API requires your BC account read or write token. Using a mid-tier “proxy” not only eliminates this security risk, but also gives you far greater control over the submitted contributions.

Allowing The User To Upload Content

This phase does not pose any big difference in requirements and solution for uploading directly into the BC backend or using a mid-tier. It consists of providing the user with a web-based upload facility. Depending on the workflow you want to implement, the upload would be accompanied by pre-defined meta tags, or some tags defined by the user, or a combination of both. The example below shows a simple Flash-based component to do just that. [flash http://brightcove.active6.com/samples/ugc/BrightcoveUpload.swf w=860h=520] The essence of the upload component here looks something like this:
// Variables to send along with upload
var sendVars:URLVariables = new URLVariables();
sendVars.action = "upload";
sendVars.tags = "predefined_1, predefined_2, user_1, user_2";
var request:URLRequest = new URLRequest();
request.data = sendVars;
request.url = "http://your.server.com/your_upload_url.php";
request.method = URLRequestMethod.POST;

//Add the user's submitted file
_refUploadFile = new FileReference();
_refUploadFile = listFiles.selectedItem.file;

//Add event handling
_refUploadFile.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);
_refUploadFile.addEventListener(Event.COMPLETE, onUploadComplete);
_refUploadFile.addEventListener(IOErrorEvent.IO_ERROR, onUploadIoError);
_refUploadFile.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onUploadSecurityError);
_refUploadFile.upload(request, "file", false);
You can of course use a plain HTML or AJAX form as well. The code for that could look like this:
  File

Tags:

Administering Submissions

As mentioned in the introduction, where you do administration of submissions depends on your security requirements and your business work flow. You probably want to review the submissions and meta values before publishing them in designated play lists. Let’s say you’re doing this on your own middle tier. Once you have approved a submission, uploading from your middle tier to the BC backend can be as simple as this call to the Media API:
define("UPLOAD_CALL", "http://api.brightcove.com/services/post");
define("TOKEN", "your_write_token_here");
define("METHOD", "create_video");

// Create arrays to send to BC Media API
$post = array();
$params = array();
$video = array();

$video["name"] = $file_name;
$video["shortDescription"] = "A User Contributed Video";
$video["tags"] = "Philips_Demo";

$params["token"] = TOKEN;
$params["video"] = $video;

$post["method"] = METHOD;
$post["params"] = $params;

$requestData["json"] = json_encode($post) . "\n";
$requestData["file"] = "@".$file_path."/".$file_name;

// Execute the call using curl
$ch = curl_init(UPLOAD_CALL);

// Request type is post
curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_NOPROGRESS, false);

// Declare the post data that we assembled earlier
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestData);

// Return the result as a string of the return value of curl_exec instead of outputting it directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Go!
$http_result = curl_exec($ch);

// Print the results if successful, otherwise print the errors :
if ($http_result)
{
     echo("$http_result");
}
else
{
	 $msg = curl_error($ch).":".curl_getinfo($ch, CURLINFO_HEADER_OUT)." (".curl_errno($ch).")";
         echo($msg);
}

Publishing Media & Administering Play Lists

Depending on your workflow this can be done on your mid-tier, using API calls similar to the one listed above, or within the BC console.

Trackback from your site.

Comments (2)

  • Bob de Wit

    |

    I’ve never actually implemented a direct upload app to Brightcove in Flex for the security reasons I mention in the article. I believe your post on the forums relates to an issue with the sequence in which Flex sends the file handle and form variables respectively. As to your forum question on retrieving the token using SSL in stead of encoding it, I don’t think it would make security much tighter since your SWF can still be decompiled easily. The only adive I can give if you do want to upload directly to Brightcove is to use something like SecureSWF or Anayeta.

    Reply

Leave a comment