Quantcast
Channel: Kaltura - Latest posts
Viewing all articles
Browse latest Browse all 7410

Upload Videos To Kaltura Using Python

$
0
0

Hello @dsingh1,

First of all, note that I’ve masked your personal information [partner ID, secret, token ID, etc]. When posting on the forum, such information should never be provided.

In your original code, I see:

uploadTokenId = "upload id"

This is wrong as it should contain the ID returned from client.uploadToken.add(uploadToken), I also see that you’ve used a hard coded entryId when you should get the ID from the object returned from client.media.add(entry)

However, I believe the real problem is with this line:

fileData = open('/path/to/file', 'r')

This would work with Python 2.n but will fail with 3.n. Instead, you should open the file in binary mode, like so:

fileData = open('/path/to/file', 'rb')

Below is a full script for ingesting a video asset onto Kaltura using the Python client library. You can run it like this:

$ ./upload.py <partner id> <admin secret> </path/to/vid_file>

For illustration purposes, I’ve used pprint() to dump the objects returned from each request.

#!/usr/bin/python
from KalturaClient import *
from KalturaClient.Plugins.Core import *
from pprint import pprint
import sys,os


if len(sys.argv) < 3:
        print ("Usage: " + sys.argv[0] + " <partner id> <admin secret> </path/to/vid_file>")
        exit (1)


partnerId=sys.argv[1]
partnerAdminSecret=sys.argv[2]
vidFile=sys.argv[3]
config = KalturaConfiguration()
config.serviceUrl = "https://www.kaltura.com/"
client = KalturaClient(config)
ks = client.session.start(
      partnerAdminSecret,
      "",
      KalturaSessionType.ADMIN,
      partnerId)
client.setKs(ks)

uploadToken = KalturaUploadToken()

result = client.uploadToken.add(uploadToken);
pprint(vars(result));
uploadTokenId = result.id
fileData = open(vidFile, 'rb')
resume = False
finalChunk = True
resumeAt = -1

result = client.uploadToken.upload(uploadTokenId, fileData, resume, finalChunk, resumeAt);
pprint(vars(result));
entry = KalturaMediaEntry()
entry.mediaType = KalturaMediaType.VIDEO
entry.name = "Test"

result = client.media.add(entry);
pprint(vars(result));
entryId = result.id
print(entryId)
resource = KalturaUploadedFileTokenResource()
resource.token = uploadTokenId

result = client.media.addContent(entryId, resource);
pprint(vars(result));

Viewing all articles
Browse latest Browse all 7410

Trending Articles