jQuery File Upload widget help

We have a custom PHP application that is currently using the Kaltura Simple Uploader (KSU) but we’ve been asked to convert it in order to get away from using Flash.

I’ve been following the documentation that I’ve found on https://developer.kaltura.com/workflows/Ingest_and_Upload_Media and am using the jQuery File Upload widget so that we can do the chunked and pause/play easily. I’ve got the file uploading but then it prints out to the console “Next, call the media.add and media.addContent API actions to create your Kaltura Media Entry and associate it with this newly uploaded file. Once media.addContent is called, the transcoding process will begin and your media entry will be prepared for playback and sharing. Use the Kaltura JS client library or call your backend service to execute media.add and media.addContent passing the uploadTokenId.”

I’ve tried multiple ways to execute the media.add and media.addContent but I’m hitting a dead end with no errors being returned and nothing extra printing in the console.

Wondering if anyone has successfully integrated this in their application and if so if there are any good examples out there that would help me.


Hi @mjokela,

I’m not sure I understand the exact situation. When trying to upload a file using the interactive tutorial here https://developer.kaltura.com/workflows/Ingest_and_Upload_Media, does it work? If it does not, please open your browser’s dev tools and check for errors under the “Console” tab as well as for failing requests under the “Network” tab.
If it works from the interactive web I/F but fails from your own code, please provide the full code and I’ll take a look.

You may also be interested in https://github.com/kaltura/kaltura-parallel-upload-resumablejs.
You can see a fully functional demo for that [working against our SaaS endpoint - www.kaltura.com] here:

Thanks, yes the workflow interactive tutorial works fine for me if I put in all the info there and try to follow along.

With the Jquery chunked library, it only gets you through the first few steps in that workflow and then it prints out to the screen that you need to finish by doing the final two steps. I’ve tried doing those two steps in multiple ways (one in javascript using the Kaltura JS API client and one in PHP using the Kaltura PHP API client). I can’t seem to get either to properly do the media.add or media.addContent.

I then decided to try to not even use the jQuery chunked library and just try to follow along the workflow and use the PHP API for everything and I can get the token created and then when I attempt to attach the file to the token I get the error “Upload failed”. I’m not sure if it is not liking the format of the file, as it doesn’t document very well what format the function in the API is expecting the file to be. I’ve tried passing a string of the name, the full path to the file, an actual stream with the file contents and they all give me that same error.

I know that this step works as I’m getting a valid value for the TokenId:
$result = $client->uploadToken->add($uploadToken);
$uploadTokenId = $result->id;

But then I attempt to get the file from the html form input and do this and this is when it fails:
$resume = false;
$finalChunk = true;
$resumeAt = -1;

$result = $client->uploadToken->upload($uploadTokenId, $fileData, $resume, $finalChunk, $resumeAt);

Thanks for sending the resumablejs Kaltura link, I’ll take a look at that one and see if that would work for me instead of these two ways I’ve tried.

Hi @mjokela,

When using the PHP client, $fileData should be a string set to the full path of your media file.
You can look at this example here:

It’s not exactly what you want since it obtains a blob created by the MediaRecord API, saves that to the disk and then uploads it to Kaltura but it should be enough for you to get the general idea.

That said, if you use https://github.com/kaltura/kaltura-parallel-upload-resumablejs you wouldn’t need the intermediate PHP code that saves the file on the server’s disk and then makes the needed API calls to upload it to the Kaltura server, it can all be done on the client side. In fact, that’s also what I’ve done in the webrtc-krecord repo I provided above, upload_to_kaltura.php is from an earlier iteration and is no longer used.

Thanks, I’ve got it saving the file onto disk from the form and verified the file does in fact exist and has content. But I’m still getting the error at the uploadToken->upload().

Here is what I have as part of my code for that section currently:

try {
$tempFileDir = “/tmp”;
$target_file = $tempFileDir . “/” . $_FILES[“asset_file”][“name”];
move_uploaded_file($_FILES[“asset_file”][“tmp_name”], $target_file);
$fileData = $target_file;

$result = $client->uploadToken->upload($uploadTokenId, $fileData, $resume, $finalChunk, $resumeAt);

} catch (Exception $e) {
echo $e->getMessage();

Below is what is displayed from the catch (removed/updated some values for security reasons):

Upload failed

array(6) { [0]=> array(6) { [“file”]=> string(72) “/fullpath/Kaltura/KalturaClient.php” [“line”]=> int(3750) [“function”]=> string(21) “throwExceptionIfError” [“class”]=> string(17) “KalturaClientBase” [“type”]=> string(2) “->” [“args”]=> array(1) { [0]=> array(4) { [“code”]=> string(12) “UPLOAD_ERROR” [“message”]=> string(13) “Upload failed” [“objectType”]=> string(19) “KalturaAPIException” [“args”]=> array(0) { } } } } [1]=> array(6) { [“file”]=> string(73) “/pathtoscript.php” [“line”]=> int(133) [“function”]=> string(6) “upload” [“class”]=> string(25) “KalturaUploadTokenService” [“type”]=> string(2) “->” [“args”]=> array(5) { [0]=> string(34) “tokenIdNumber” [1]=> string(31) “/tmp/Kaltura_Logo_Animation.flv” [2]=> bool(false) [3]=> bool(true) [4]=> int(-1) } } [2]=> array(6) { [“file”]=> string(79) “/pathToFrameworkScript.php” [“line”]=> int(55) [“function”]=> string(6) “Action” [“class”]=> string(9) “ActionName” [“type”]=> string(2) “->” [“args”]=> array(0) { } } [3]=> array(6) { [“file”]=> string(67) “/Controller.php” [“line”]=> int(35) [“function”]=> string(13) “functionName” [“class”]=> string(13) “className” [“type”]=> string(2) “->” [“args”]=> array(1) { [0]=> &NULL } } [4]=> array(6) { [“file”]=> string(81) “/PathToController.php” [“line”]=> int(55) [“function”]=> string(10) “Controller” [“class”]=> string(10) “Controller” [“type”]=> string(2) “->” [“args”]=> array(0) { } } [5]=> array(6) { [“file”]=> string(39) “/pathto/index.php” [“line”]=> int(13) [“function”]=> string(15) “functionName” [“class”]=> string(15) “className” [“type”]=> string(2) “->” [“args”]=> array(0) { } } }

Hi @mjokela,

Are you sure $fileData contains a valid path on disk?

I recommend creating a PHP snippet that accepts the file path as the first arg and makes all the needed requests and executing it from a shell on that server. Let’s see how that goes. If that too fails, it will still be easier to debug than a flow that involves submitting a form in browser context, if it succeeds then at least you’ve isolated the issue.

If you look at the following from the trace, it looks to have a valid path.

And if I login to the console I can see that file exists at that path:
ls -la /tmp/Kaltura_Logo_Animation.flv
-rw-r–r-- 1 username group 498318 Mar 26 11:44 /tmp/Kaltura_Logo_Animation.flv

I’ll try doing it as a small shell script and see if I get the same error and report back.

I think I figured it out. Thanks so much for your help as it helped to know that I was handling the file ok. Thinking it was a permission issue with the file on the one server.


You’re welcome, @mjokela. Glad to hear we’re good:)

Can I ask one other question…I’ve got this working but I’ve had to hardcode the ServiceUrl into the code instead of pulling from my config file. If I try pulling from the config by doing the following I get an error “'failed to unserialize server result”:

$config = new KalturaConfiguration($partnerID);
$config->serviceUrl = $serviceUrl;
$config->format = KalturaClientBase::KALTURA_SERVICE_FORMAT_PHP;
$client = new KalturaClient($config);

Do you know why I would get that error if reading from a config file vs hardcoding the exact same value in the $config->serviceUrl variable above?

Add a debug print for $serviceUrl and let’s see what the value is.

I’ve done that and it is exactly the same as what I was hardcoding in.

Without looking at the actual code and config files, I’m afraid I can’t help you spot the issue…
I’m guessing it may have to do with the carriage return and UNIX/Linux vs Windows [\r\n vs \n] or else there’s some other trailing char there but it’s only a guess.

I can also recommend is that you edit:
KalturaClientBase.php so that, right before:

$result = curl_exec($ch);

You have:

curl_setopt($ch, CURLOPT_VERBOSE, 1);

Then run it from the shell and see exactly what the request looks like and compare it with what it looks like when you use a literal string when setting $config->serviceUrl

Thanks, I’ll make this change and see what it says. I even surrounded the values with … so that I knew that there weren’t extra spaces.

I added this and it looks like it is getting the fatal error before getting to the curl command.

I’ve tracked the error down to this code within that same file but I still wasn’t sure why it was failing with the unserialize command.

       if ($this->config->format == self::KALTURA_SERVICE_FORMAT_PHP)
			$result = @unserialize($postResult);

			if ($result === false && serialize(false) !== $postResult) 
				throw new KalturaClientException("failed to unserialize server result\n$postResult", KalturaClientException::ERROR_UNSERIALIZE_FAILED);
			$dump = print_r($result, true);

// if(strlen($dump) < 1024)
$this->log("result (object dump): " . $dump);

It fails when attempting to unserialize() $postResult. Dump $postResult and let’s see what it looks like.

checking that variable at the point of unserialize is the following:

302 Found


The document has moved here.

Apache Server at kaltura.com Port 80

Please provide the full PHP snippet and the config file you’re reading from while masking your partner ID and secret but providing the serviceUrl line as is.
I’ll take a look.

Here is the config file contents:

define('KALTURA_PARTNER_ID' ,xxxxxx);
define('KALTURA_USER_SECRET' ,"xxxxxxx");
define('KALTURA_ADMIN_SECRET' , "xxxxx");
define('KALTURA_SERVICE_URL' ,"https://kaltura.com");
define('KALTURA_UICONFID' ,xxxxx);

Here is where I add the session:

         //define session variables
        $partnerUserID          = KALTURA_USER;
        $partnerID              = KALTURA_PARTNER_ID;
        $serviceUrl             = KALTURA_SERVICE_URL;
        $adminSecret            = KALTURA_ADMIN_SECRET;
        $sessionExpiry          = 86400;
        $sessionPrivileges      = '';

        $config = new KalturaConfiguration($partnerID);
        $config->serviceUrl = $serviceUrl;
        $config->format = KalturaClientBase::KALTURA_SERVICE_FORMAT_PHP;
        $client = new KalturaClient($config);
        $ks = $client->session->start(

Thanks so much for helping me figure this out! Also it would be nice to know if the ServiceUrl is something that we should be keeping out of git for security reasons or if we can’t figure this out if it is ok keeping it hardcoded directly for now.

Change to:

define('KALTURA_SERVICE_URL' ,"https://www.kaltura.com");

Also, no need to assign the consts into variables and then use these, you can just use the consts directly.