Kaltura文件上传API

时间:2015-10-26 13:37:58

标签: java kaltura

我必须使用java kaltura api上传文件。我搜索了很多,但找不到任何帮助文档。如果有人知道如何使用java在kaltura上传文件,请帮助我。

我有一个用于文件上传的C#API,我希望它能帮到你。

KalturaClient  kalturaClient = KalturaUtilsService.getKalturaClient();
            KalturaMediaEntry kalturaMediaEntry = new KalturaMediaEntry();


            kalturaMediaEntry.name = "Java Entry Using C#";
            kalturaMediaEntry.mediaType = KalturaMediaType.VIDEO;
            kalturaMediaEntry = kalturaClient.getMediaService().add(kalturaMediaEntry);
            FileStream fileStream = new FileStream("/home/alok/Desktop/index.mp4", FileMode.Open, FileAccess.Read);
            KalturaUploadToken uploadToken = kalturaClient.UploadTokenService.Add();
            kalturaClient.UploadTokenService.Upload(uploadToken.Id, fileStream);

            KalturaUploadedFileTokenResource mediaResource = new KalturaUploadedFileTokenResource();
            mediaResource.Token = uploadToken.Id;
            kalturaMediaEntry = kalturaClient.MediaService.AddContent(kalturaMediaEntry.Id, mediaResource);

提前致谢!!!

1 个答案:

答案 0 :(得分:3)

您可以在src/Kaltura.java下找到java客户端库(http://www.kaltura.com/api_v3/testme/client-libs.php)提供的示例,方法uploadMediaFileAndAttachToEmptyEntry

这是一个简化版本:

String adminSecret = "API-ADMIN-SECRET";
Integer partnerId = PARTNER_ID;
String filePath = "src/DemoVideo.flv";
String uploadUserId = "TestUploader";

// initialize the client
KalturaConfiguration config = new KalturaConfiguration();
config.setEndpoint("http://www.kaltura.com/");
KalturaClient client = new KalturaClient(config);
String ks = client.generateSession(adminSecret, uploadUserId, KalturaSessionType.ADMIN, partnerId);
client.setKs(ks);

// add the media entry
KalturaMediaEntry mediaEntry = new KalturaMediaEntry();
mediaEntry.name = "Uploaded Media";
mediaEntry.mediaType = KalturaMediaType.VIDEO;
mediaEntry = client.getMediaService().add(mediaEntry);

// add the upload token
KalturaUploadToken uploadToken = new KalturaUploadToken();
uploadToken = client.getUploadTokenService().add(uploadToken);

// initialize the file
File file = new File(filePath);

// upload the file
client.getUploadTokenService().upload(uploadToken.id, file);

// link between the file and the media entry
KalturaUploadedFileTokenResource uploadedFileTokenResource = new KalturaUploadedFileTokenResource();
uploadedFileTokenResource.token = uploadToken.id;
client.getMediaService().addContent(mediaEntry.id, uploadedFileTokenResource);