Prabjot Singh Prabjot Singh - 5 months ago 22
Node.js Question

Kaltura: MISSING_MANDATORY_PARAMETER,uploadTokenId

I am trying to upload file in kaltura using nodejs npm package 'kaltura', it is consistently showing me below error

<?xml version="1.0" encoding="utf-8"?><xml><result><error><objectType>KalturaAPIException</objectType><code>MISSING_MANDATORY_PARAMETER</code><message>Missing parameter &quot;uploadTokenId&quot;</message><args><item><objectType>KalturaApiExceptionArg</objectType><name>PARAM_NAME</name><value>uploadTokenId</value></item></args></error></result><executionTime>0.002338171005249</executionTime></xml>


it is asking me to add uploadTokenId even i have already added. Even it is giving me this error in small files like 2mb.

kaltura npm verison

"kaltura": "^3.3.1"


Upload token code

var configureKalturaClient = function(){

var config = new kaltura.kc.KalturaConfiguration(12345);
console.log(JSON.stringify(config))
var client = new kaltura.kc.KalturaClient(config);
var sessionID = null;
client.session.start(function(ks) {
if (ks.code && ks.message) {
console.log('Error starting session', ks);
} else {
client.setKs(ks);

console.log("kaltura session-->" + ks)

var uploadTokenId = "12345dddd122333";

var fileData = "/home/alok/Downloads/Delhi.jpg";

var resume = false;

var finalChunk = false;

var resumeAt = "";
client.uploadToken.upload(function(results) {
if (results && results.code && results.message) {
console.log('Kaltura Error', results);
} else {
console.log('Kaltura Result', results);
}
},
uploadTokenId,
fileData,
resume,
finalChunk,
resumeAt);

}
}, "121334345455",
"myemail9@gmail.com",
kaltura.kc.enums.KalturaSessionType.ADMIN,
12345)

}


Thanks

Answer

In kaltura 3.3.1, the KalturaClientBase.js has a potential bug in the doHttpRequest function. Consider the following loc in the doHttpRequest function:

var debugUrl = requestUrl + '?' + data;

Here, data returns "undefined" in your case.

So, update the doHttpRequest function as follows:

    KalturaClientBase.prototype.doHttpRequest = function (callCompletedCallback, requestUrl, params, files) {

        var data = http_build_query(params);
        var that = this;
        var requestIndex = KalturaClientBase.requestIndex++;
        var debugUrl = requestUrl + '?' + data;
        var urlInfo = url.parse(debugUrl);
        this.log('Request [' + requestIndex + ']: ' + debugUrl);
        var options = {
            host : urlInfo.host,
            path : urlInfo.path,
            method : 'POST'
        };

        if(Object.keys(files).length > 0){
            var crlf = '\r\n';
            var boundary = '---------------------------' + Math.random();
            var delimiter = crlf + '--' + boundary;
            var postData = [];

            for ( var key in files) {
                var filePath = files[key];
                var fileName = path.basename(filePath);
                var data = fs.readFileSync(filePath);
                var headers = [ 'Content-Disposition: form-data; name="' + key + '"; filename="' + fileName + '"' + crlf, 'Content-Type: application/octet-stream' + crlf ];

                postData.push(new Buffer(delimiter + crlf + headers.join('') + crlf));
                postData.push(new Buffer(data));
            }
            postData.push(new Buffer(delimiter + '--'));
            var multipartBody = Buffer.concat(postData);

            options.headers = {
                'Content-Type': 'multipart/form-data; boundary=' + boundary,
                'Content-Length': multipartBody.length
            };
            sendRequestHelper(that, options, multipartBody, requestIndex, callCompletedCallback, this.config.timeout);

        } else {
            var data = http_build_query(params);
            options.headers = {
                'Content-Type' : 'application/x-www-form-urlencoded',
                'Content-Length' : Buffer.byteLength(data)
            };
            sendRequestHelper(that, options, data, requestIndex, callCompletedCallback);
        }
};

I hope it works.