Created
March 4, 2015 23:15
-
-
Save varmab/612aec4b14bcd9f5c476 to your computer and use it in GitHub Desktop.
Uploading video using Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment