Nodejs:Path 必须是没有空字节的字符串
Nodejs:Path must be a string without null bytes
我正在尝试将视频上传到 kaltura,但它显示以下错误
Uploading file
file path /home/alok/Downloads/video.mp4
true
upload token added {"id":"######","partnerId":####,"userId":"######","status":0,"createdAt":1467038066,"updatedAt":1467038066,"objectType":"KalturaUploadToken"}
{
"date": "Mon Jun 27 2016 20:04:16 GMT+0530 (IST)",
"process": {
"pid": 13534,
"uid": 1001,
"gid": 1001,
"cwd": "/home/alok/Desktop/projects/myproject",
"execPath": "/usr/local/nodejs/bin/node",
"version": "v4.4.5",
"argv": [
"/usr/local/nodejs/bin/node",
"/home/alok/Desktop/projects/myproject/app.js"
],
"memoryUsage": {
"rss": 85884928,
"heapTotal": 77003616,
"heapUsed": 52299120
}
},
"os": {
"loadavg": [
1.21826171875,
1.08837890625,
0.89111328125
],
"uptime": 31013
},
"trace": [
{
"column": 14,
"file": "fs.js",
"function": "nullCheck",
"line": 94,
"method": null,
"native": false
},
{
"column": 3,
"file": "fs.js",
"function": "Object.fs.openSync",
"line": 548,
"method": "fs.openSync",
"native": false
},
{
"column": 15,
"file": "fs.js",
"function": "Object.fs.readFileSync",
"line": 397,
"method": "fs.readFileSync",
"native": false
},
{
"column": 18,
"file": "/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaClientBase.js",
"function": "KalturaClientBase.doHttpRequest",
"line": 433,
"method": "doHttpRequest",
"native": false
},
{
"column": 7,
"file": "/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaClientBase.js",
"function": "KalturaClientBase.doQueue",
"line": 336,
"method": "doQueue",
"native": false
},
{
"column": 15,
"file": "/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaServices.js",
"function": "KalturaUploadTokenService.upload",
"line": 7120,
"method": "upload",
"native": false
},
{
"column": 47,
"file": "/home/alok/Desktop/projects/myproject/application/services/project/projectService.js",
"function": null,
"line": 50,
"method": null,
"native": false
},
{
"column": 4,
"file": "/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaClientBase.js",
"function": "",
"line": 389,
"method": null,
"native": false
},
{
"column": 20,
"file": "events.js",
"function": "emitNone",
"line": 72,
"method": null,
"native": false
},
{
"column": 7,
"file": "events.js",
"function": "IncomingMessage.emit",
"line": 166,
"method": "emit",
"native": false
},
{
"column": 12,
"file": "_stream_readable.js",
"function": "endReadableNT",
"line": 913,
"method": null,
"native": false
},
{
"column": 9,
"file": "node.js",
"function": "nextTickCallbackWith2Args",
"line": 442,
"method": null,
"native": false
},
{
"column": 17,
"file": "node.js",
"function": "process._tickCallback",
"line": 356,
"method": "_tickCallback",
"native": false
}
],
"stack": [
"Error: Path must be a string without null bytes.",
" at nullCheck (fs.js:94:14)",
" at Object.fs.openSync (fs.js:548:3)",
" at Object.fs.readFileSync (fs.js:397:15)",
" at KalturaClientBase.doHttpRequest (/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaClientBase.js:433:18)",
" at KalturaClientBase.doQueue (/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaClientBase.js:336:7)",
" at KalturaUploadTokenService.upload (/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaServices.js:7120:15)",
" at /home/alok/Desktop/projects/myproject/application/services/project/projectService.js:50:47",
" at IncomingMessage.<anonymous> (/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaClientBase.js:389:4)",
" at emitNone (events.js:72:20)",
" at IncomingMessage.emit (events.js:166:7)",
" at endReadableNT (_stream_readable.js:913:12)",
" at nextTickCallbackWith2Args (node.js:442:9)",
" at process._tickCallback (node.js:356:17)"
],
"level": "error",
"message": "uncaughtException: Path must be a string without null bytes."
}
我认为 fs 读取有问题,即使指定路径上有文件。
kaltura 上的文件上传
var KalturaConstants = require('./KalturaTypes.js');
var Kaltura = require('./KalturaClient.js');
var KalturaClient = null;
var Session = null;
var pager = new Kaltura.objects.KalturaFilterPager();
pager.pageSize=10000;
pager.pageIndex=1;
var KALTURA_PARTNERID="#####";
var KALTURA_ADMINSECRET="##################";
var KALTURA_USERID="####";
var initialize = function(callback) {
var config = new Kaltura.KalturaConfiguration(parseInt(KALTURA_PARTNERID));
KalturaClient = new Kaltura.KalturaClient(config);
KalturaClient.session.start(function(session) {
KalturaClient.setKs(session);
Session = session;
callback();
}, KALTURA_ADMINSECRET, KALTURA_USERID, KalturaConstants.KalturaSessionType.ADMIN,
parseInt(KALTURA_PARTNERID), '10000000');
}
var uploadMedia = function(videoFile,userId) {
var fs = require("fs");
var DOWNLOAD_DIR = './downloads/';
var fileWithPath=DOWNLOAD_DIR+videoFile;
fs.exists(fileWithPath, function(exists) {
if (exists) {
fs.readFile(fileWithPath, "utf8", function(error, data) {
var uploadToken = null;
KalturaClient.uploadToken.add(function(token){
console.log("upload token added " + JSON.stringify(token));
KalturaClient.uploadToken.upload(function(token){
console.log("upload token uploaded " + JSON.stringify(token));
var entry = new Kaltura.objects.KalturaMediaEntry();
entry.name = "My Video";
entry.description = "My video";
entry.userId = userId;
entry.creatorId = userId;
entry.type = KalturaConstants.KalturaEntryType.AUTOMATIC;
entry.mediaType = KalturaConstants.KalturaMediaType.VIDEO;
entry.sourceType = KalturaConstants.KalturaSourceType.FILE;
KalturaClient.media.add(function(result){
console.log("media entry added " + JSON.stringify(result));
var resource = new Kaltura.objects.KalturaUploadedFileTokenResource();
resource.token = token.id;
KalturaClient.media.addContent(function(result2){
//if(err) console.log('Failed to add content ' + JSON.stringify(err));
console.log("media entry updated with content " + JSON.stringify(result2));
}, result.id, resource);
},entry);
},token.id,data);
}, uploadToken);
});
}
});
}
initialize(function () {
console.log('Uploading file');
uploadMedia('main_OUTPUT.tmp.mp4',1901);
});
请帮忙,我是 node.js 的新手。
谢谢
我必须以字符串形式提供文件路径,并且以字节为单位提供文件数据。所以用 "/opt/video.mp4"
之类的字符串路径替换 "data" 就可以了。
我正在尝试将视频上传到 kaltura,但它显示以下错误
Uploading file
file path /home/alok/Downloads/video.mp4
true
upload token added {"id":"######","partnerId":####,"userId":"######","status":0,"createdAt":1467038066,"updatedAt":1467038066,"objectType":"KalturaUploadToken"}
{
"date": "Mon Jun 27 2016 20:04:16 GMT+0530 (IST)",
"process": {
"pid": 13534,
"uid": 1001,
"gid": 1001,
"cwd": "/home/alok/Desktop/projects/myproject",
"execPath": "/usr/local/nodejs/bin/node",
"version": "v4.4.5",
"argv": [
"/usr/local/nodejs/bin/node",
"/home/alok/Desktop/projects/myproject/app.js"
],
"memoryUsage": {
"rss": 85884928,
"heapTotal": 77003616,
"heapUsed": 52299120
}
},
"os": {
"loadavg": [
1.21826171875,
1.08837890625,
0.89111328125
],
"uptime": 31013
},
"trace": [
{
"column": 14,
"file": "fs.js",
"function": "nullCheck",
"line": 94,
"method": null,
"native": false
},
{
"column": 3,
"file": "fs.js",
"function": "Object.fs.openSync",
"line": 548,
"method": "fs.openSync",
"native": false
},
{
"column": 15,
"file": "fs.js",
"function": "Object.fs.readFileSync",
"line": 397,
"method": "fs.readFileSync",
"native": false
},
{
"column": 18,
"file": "/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaClientBase.js",
"function": "KalturaClientBase.doHttpRequest",
"line": 433,
"method": "doHttpRequest",
"native": false
},
{
"column": 7,
"file": "/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaClientBase.js",
"function": "KalturaClientBase.doQueue",
"line": 336,
"method": "doQueue",
"native": false
},
{
"column": 15,
"file": "/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaServices.js",
"function": "KalturaUploadTokenService.upload",
"line": 7120,
"method": "upload",
"native": false
},
{
"column": 47,
"file": "/home/alok/Desktop/projects/myproject/application/services/project/projectService.js",
"function": null,
"line": 50,
"method": null,
"native": false
},
{
"column": 4,
"file": "/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaClientBase.js",
"function": "",
"line": 389,
"method": null,
"native": false
},
{
"column": 20,
"file": "events.js",
"function": "emitNone",
"line": 72,
"method": null,
"native": false
},
{
"column": 7,
"file": "events.js",
"function": "IncomingMessage.emit",
"line": 166,
"method": "emit",
"native": false
},
{
"column": 12,
"file": "_stream_readable.js",
"function": "endReadableNT",
"line": 913,
"method": null,
"native": false
},
{
"column": 9,
"file": "node.js",
"function": "nextTickCallbackWith2Args",
"line": 442,
"method": null,
"native": false
},
{
"column": 17,
"file": "node.js",
"function": "process._tickCallback",
"line": 356,
"method": "_tickCallback",
"native": false
}
],
"stack": [
"Error: Path must be a string without null bytes.",
" at nullCheck (fs.js:94:14)",
" at Object.fs.openSync (fs.js:548:3)",
" at Object.fs.readFileSync (fs.js:397:15)",
" at KalturaClientBase.doHttpRequest (/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaClientBase.js:433:18)",
" at KalturaClientBase.doQueue (/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaClientBase.js:336:7)",
" at KalturaUploadTokenService.upload (/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaServices.js:7120:15)",
" at /home/alok/Desktop/projects/myproject/application/services/project/projectService.js:50:47",
" at IncomingMessage.<anonymous> (/home/alok/Desktop/projects/myproject/node_modules/kaltura/KalturaClientBase.js:389:4)",
" at emitNone (events.js:72:20)",
" at IncomingMessage.emit (events.js:166:7)",
" at endReadableNT (_stream_readable.js:913:12)",
" at nextTickCallbackWith2Args (node.js:442:9)",
" at process._tickCallback (node.js:356:17)"
],
"level": "error",
"message": "uncaughtException: Path must be a string without null bytes."
}
我认为 fs 读取有问题,即使指定路径上有文件。
kaltura 上的文件上传
var KalturaConstants = require('./KalturaTypes.js');
var Kaltura = require('./KalturaClient.js');
var KalturaClient = null;
var Session = null;
var pager = new Kaltura.objects.KalturaFilterPager();
pager.pageSize=10000;
pager.pageIndex=1;
var KALTURA_PARTNERID="#####";
var KALTURA_ADMINSECRET="##################";
var KALTURA_USERID="####";
var initialize = function(callback) {
var config = new Kaltura.KalturaConfiguration(parseInt(KALTURA_PARTNERID));
KalturaClient = new Kaltura.KalturaClient(config);
KalturaClient.session.start(function(session) {
KalturaClient.setKs(session);
Session = session;
callback();
}, KALTURA_ADMINSECRET, KALTURA_USERID, KalturaConstants.KalturaSessionType.ADMIN,
parseInt(KALTURA_PARTNERID), '10000000');
}
var uploadMedia = function(videoFile,userId) {
var fs = require("fs");
var DOWNLOAD_DIR = './downloads/';
var fileWithPath=DOWNLOAD_DIR+videoFile;
fs.exists(fileWithPath, function(exists) {
if (exists) {
fs.readFile(fileWithPath, "utf8", function(error, data) {
var uploadToken = null;
KalturaClient.uploadToken.add(function(token){
console.log("upload token added " + JSON.stringify(token));
KalturaClient.uploadToken.upload(function(token){
console.log("upload token uploaded " + JSON.stringify(token));
var entry = new Kaltura.objects.KalturaMediaEntry();
entry.name = "My Video";
entry.description = "My video";
entry.userId = userId;
entry.creatorId = userId;
entry.type = KalturaConstants.KalturaEntryType.AUTOMATIC;
entry.mediaType = KalturaConstants.KalturaMediaType.VIDEO;
entry.sourceType = KalturaConstants.KalturaSourceType.FILE;
KalturaClient.media.add(function(result){
console.log("media entry added " + JSON.stringify(result));
var resource = new Kaltura.objects.KalturaUploadedFileTokenResource();
resource.token = token.id;
KalturaClient.media.addContent(function(result2){
//if(err) console.log('Failed to add content ' + JSON.stringify(err));
console.log("media entry updated with content " + JSON.stringify(result2));
}, result.id, resource);
},entry);
},token.id,data);
}, uploadToken);
});
}
});
}
initialize(function () {
console.log('Uploading file');
uploadMedia('main_OUTPUT.tmp.mp4',1901);
});
请帮忙,我是 node.js 的新手。
谢谢
我必须以字符串形式提供文件路径,并且以字节为单位提供文件数据。所以用 "/opt/video.mp4"
之类的字符串路径替换 "data" 就可以了。