首页 文章

Kaltura:MISSING_MANDATORY_PARAMETER,uploadTokenId

提问于
浏览
0

我正在尝试使用nodejs npm package'kaltura'上传kaltura中的文件,它始终显示我下面的错误

<?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>

它要求我添加uploadTokenId,即使我已经添加了 . 即使它在像2mb这样的小文件中给我这个错误 .

kaltura npm verison

"kaltura": "^3.3.1"

上传令牌代码

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)

    }

谢谢

1 回答

  • 0

    在kaltura 3.3.1中,KalturaClientBase.js在doHttpRequest函数中存在潜在的错误 . 考虑doHttpRequest函数中的以下loc:

    var debugUrl = requestUrl + '?' + data;
    

    在这里,数据在您的情况下返回“undefined” .

    因此,更新doHttpRequest函数如下:

    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);
            }
    };
    

    我希望它有效 .

相关问题