文化:MISSING_MANDATORY_PARAMETER,uploadTokenId
Kaltura: MISSING_MANDATORY_PARAMETER,uploadTokenId
我正在尝试使用 nodejs npm 包在 kaltura 中上传文件 'kaltura',它始终显示以下错误
<?xml version="1.0" encoding="utf-8"?><xml><result><error><objectType>KalturaAPIException</objectType><code>MISSING_MANDATORY_PARAMETER</code><message>Missing parameter "uploadTokenId"</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)
}
谢谢
在 kaltura 3.3.1 中,KalturaClientBase.js 在 doHttpRequest 函数中有一个潜在的错误。考虑 doHttpRequest 函数中的以下位置:
var debugUrl = requestUrl + '?' + data;
这里,数据 returns "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);
}
};
希望有用。
我正在尝试使用 nodejs npm 包在 kaltura 中上传文件 'kaltura',它始终显示以下错误
<?xml version="1.0" encoding="utf-8"?><xml><result><error><objectType>KalturaAPIException</objectType><code>MISSING_MANDATORY_PARAMETER</code><message>Missing parameter "uploadTokenId"</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)
}
谢谢
在 kaltura 3.3.1 中,KalturaClientBase.js 在 doHttpRequest 函数中有一个潜在的错误。考虑 doHttpRequest 函数中的以下位置:
var debugUrl = requestUrl + '?' + data;
这里,数据 returns "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);
}
};
希望有用。