Cannot upload using TestDemo script

Hello,
i configured config.ini and trying to upload using php cli client. configured the adminsecret,serviceurl and partner id and getting a :slight_smile:
PHP Fatal error: Uncaught KalturaClientException: Uploading files is not supported with stream context http request, please use curl. in /tmp/php5/KalturaClientBase.php:608
Stack trace:
#0 /tmp/php5/KalturaClientBase.php(477): KalturaClientBase->doPostRequest(‘http://cdn-02.h…’, Array, Array)
#1 /tmp/php5/KalturaClientBase.php(351): KalturaClientBase->doHttpRequest(‘http://cdn-02.h…’, Array, Array)
#2 /tmp/php5/KalturaClient.php(1074): KalturaClientBase->doQueue()
#3 /tmp/php5/TestCode/TestMain.php(127): KalturaBaseEntryService->upload(‘DemoVideo.flv’)
#4 /tmp/php5/TestCode/TestMain.php(58): TestMain->add()
#5 /tmp/php5/TestCode/TestMain.php(145): TestMain::run()
#6 {main}
thrown in /tmp/php5/KalturaClientBase.php on line 608

Can you please help?

Hi @OCX,

Please share your full code.
As reference, you can take a look at this script:

Which is run as part of kaltura-sanity.sh

Hello Jess,

I am following the workflow tutorial, i was able to generate a token id and now trying to send the data usng that id as a next step. I get the following:

KalturaFullClient.min.js:684 Uncaught TypeError: Cannot read property '0' of undefined
    at KalturaRequestBuilder.doHttpRequest (KalturaFullClient.min.js:684)
    at KalturaRequestBuilder.execute (KalturaFullClient.min.js:694)
    at test3.html:26
    at Object.success (KalturaFullClient.min.js:690)
    at i (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at A (jquery.min.js:4)
    at XMLHttpRequest.<anonymous> (jquery.min.js:4)

Here is my js code:

  6 var config = new KalturaConfiguration();
  7 config.serviceUrl = 'http://....';
  8 var client = new KalturaClient(config);
  9 KalturaSessionService.start(
 10     "...",
 11     "....",
 12     2,
 13     101)
 14 .execute(client, function(success, ks) {
 15   if (!success || (ks.code && ks.message)) {
 16     console.log('Error starting session', success, ks);
 17   } else {
 18     client.setKs(ks);
 19     var uploadTokenId = "0_5bb8755914bc3175eb90692664929484";
 20     var fileData = "/var/www/html/js/a.flv";
 21     var resume = false;
 22     var finalChunk = true;
 23     var resumeAt = -1;
 24 
 25     KalturaUploadTokenService.upload(uploadTokenId, fileData, resume, finalChunk, resumeAt)
 26       .execute(client, function(success, results) {
 27         if (!success || (results && results.code && results.message)) {
 28           console.log('Kaltura Error', success, results);
 29         } else {
 30           console.log('Kaltura Result', results);
 31         }
 32       });
 33 
 34   }
 35 });
 36 
 37

Hi @OCX,

In JS, you cannot get a direct file handle with:

var fileData = "/var/www/html/js/a.flv";

It won’t work. Also, modern browsers will all block:

var fileData = "file:///var/www/html/js/a.flv";

You can use the HTML5 File APIs to read a file but I believe what you really want is for the user to select a file interactively anyhow. If that’s NOT what you want, then maybe you’re better off using the NodeJS client instead?
You can see a full code sample here:

Dependsing on your needs, you may want to consider using https://github.com/kaltura/kaltura-parallel-upload-resumablejs instead. This is a pure JS implementation that utilises https://github.com/23/resumable.js and does not rely on our JS client. It supports uploading several chunks in parallel for faster processing of big flies. It’s FOSS and you’re welcome to use it and make changes to it as you please.

Assuming you do wish to write your own code and interactive I/F using the JS client, here is a fully working, bare bones example. Of course it should not be used exactly as is.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="KalturaClient.min.js"></script>
<script src="KalturaSessionService.min.js"></script>
<script src="KalturaMediaService.min.js"></script>
<script src="KalturaUploadTokenService.min.js"></script>


<script>
  function upload() {
  var config = new KalturaConfiguration();
  config.serviceUrl = 'https://www.kaltura.com';
  var client = new KalturaClient(config);
  // Note: this is meant only as a sample.
  // You should NEVER generate sessions on the client,
  // as this exposes your Admin Secret to users.
  // Instead, generate a session on the server and pass the
  // KS to the client.
  KalturaSessionService.start(
        "YOUR_ADMIN_SECRET",
        "YOUR_USER_ID",
        2,
        YOUR_PARTNER_ID)
  .execute(client, function(success, ks) {
    if (!success || (ks.code && ks.message)) {
      console.log('Error starting session', success, ks);
    } else {
      client.setKs(ks);
        var uploadToken = {objectType: "KalturaUploadToken"};
        KalturaUploadTokenService.add(uploadToken)
        .execute(client, function(success, results) {
            if (!success || (results && results.code && results.message)) {
                console.log('Kaltura Error', success, results);
            } else {
                console.log('Kaltura Result', results);
                var uploadTokenId = results.id;

                var resume = false;
                var finalChunk = true;
                var resumeAt = -1;
                KalturaUploadTokenService.upload(uploadTokenId, document.getElementById("fileData"), resume, finalChunk, resumeAt)
                    .execute(client, function(success, results) {
                    if (!success || (results && results.code && results.message)) {
                        console.log('Kaltura Error', success, results);
                    } else {
                        console.log('Kaltura Result', results);
                        var entry = {objectType: "KalturaMediaEntry"};
                        entry.mediaType = 1 /* KalturaMediaType.VIDEO */;
                        entry.name = "test";

                        KalturaMediaService.add(entry)
                        .execute(client, function(success, results) {
                            if (!success || (results && results.code && results.message)) {
                                console.log('Kaltura Error', success, results);
                            } else {
                                console.log('Kaltura Result', results);
                                console.log(results);
                                var entryId=results.id;
                                var resource = {objectType: "KalturaUploadedFileTokenResource"};
                                resource.token = uploadTokenId;

                                KalturaMediaService.addContent(entryId, resource)
                                .execute(client, function(success, results) {
                                    if (!success || (results && results.code && results.message)) {
                                        console.log('Kaltura Error', success, results);
                                    } else {
                                        console.log('Kaltura Result', results);
                                    }
                                });
                            }

                        });
                    }
                });
            }
        });
      }
  });
}

</script>
<input type="file" id="fileData" name="filedata" />
<input type="button" onclick="upload()" value="Upload to Kaltura" />

Hi @OCX,

Please see my revised response above.

1 Like