Upload question

16 replies [Last post]
Joined: 09/09/2009
Points: 2

Hi there,

I'm new to Kaltura and I have a question about upload of video files. I have a HTML form with browse and sumbit buttons on it. When user submits the form, choosen file should be uploaded on Kaltura server so I can fetch that file later by using listEntries method for example. This means that I don't want to use any online tool or extension to make upload operational, I want to write upload workflow by myself in PHP. I'm already familiar with sessions, ks and other related stuff and I already managed to implement listEntries method, but I can't figure out how this upload should be implemented. What I found in documentation is that upload should be executed before AddEntry method. Is there any example of PHP5 code I can take a look into or can you give me any directions how to achieve upload of video files from PHP code without using embedded tools?

Tnx in advance.

Joined: 01/05/2009
Points: 1697

Hi,

You can use a simple HTML form to upload files, and then use the id from the response to call addEntry. (this is the way the TestMe Console works).

<form enctype="multipart/form-data" method="post" action="http://www.kaltura.com/api_v3/index.php?service=media&action=upload">
        <input type="text" name="ks" />
        <input type="file" class="disabled" name="fileData"/>
        <input type="submit"/>
</form>

However, this method is not recommended, as you will not be able do design the result page due to cross-site limitations.

So especially for this - we created the Simple Uploader Widget that enables uploading of files using an flash widget that will only contain the "Browse" button.

Remember to call addEntry api after performing upload.

Joined: 10/05/2009
Points: 3

Hi,
Iam a new member to Kaltura community.
I am facing issue with Upload API with my client integration.

I am looking forward to Upload mix and media files through my application.

The flow which iam following is :

1.Get the session using StartSession API.---- success
2. Upload media /mix ---returning "500 Server Internal Error..."

My questions are :
1.Is there any prerequisite to using UPLOAD API apart from StartSession API.

2.What is the flow for using Upload API.

Joined: 10/10/2009
Points: 1

I also used a simple upload html form . and used api upload method.
and then cal addEntry or addDataEntry method both works, but file not shown in account. new entry added to entry list but file doesont show there. Please explain why it happends?

Joined: 04/05/2009
Points: 354

Can you find out the specifics of the internal server error? You may have to look at the logs for your server...

Joined: 10/05/2009
Points: 3

i am successfully able to get session, upload the file to the kaltura, able to add entry for the uploaded media , but it is showing empty media , on Kaltura account.,please let me know what iam missing here ..

Joined: 01/05/2009
Points: 1697

Hi Guys,

The API provides form-multipart upload method.
That means that you need to construct a multipart request in order to upload the files.

If you use an html form (like in the above example), a multipart request is constructed for you when performing the submit upload action.
On other environments where you're not inside the browser or don't have multipart requests - such request should be constructed (as it is being done on the client libraries as well).

To sum it up, the option are as follow:

  • Use html form to upload (limited by cross-site scripting, so you can't handle the requests).
  • Use the Simple Uploader Widget widget to upload the files and integrate through it's APIs.
  • Construct a multipart request in your programming language of choice (php, java, as3, flex and c# users can use the Kaltura client libraries).
Joined: 11/17/2010
Points: 46

Anyone able to get a purely html/php upload to work...ie upload to user and transcode to flavors?

Joined: 01/04/2011
Points: 17

I'm also trying to write html/php page, using the api to upload videos, but am having no luck so far. At the moment I'm getting an error 'Error while starting session for partner [100]' - but this is to do with setting up the session to start with rather than the actual upload.

Would be interested to see someone's code if they have got this working. If I can figure it out, I'll post the code up.
Cheers,
Alex

Joined: 01/04/2011
Points: 17

OK, I've got the session error resolved ( had the wrong partnerSecret).

So now I'm getting the error: "failed creating formpost data", from the code:


require_once('config.php');
require_once('client/KalturaClient.php');
$config = new KalturaConfiguration($lconfig->partnerId);
$config->serviceUrl = $lconfig->url;
$client = new KalturaClient($config);
$ks = $client->session->start($lconfig->partnerSecret, $lconfig->partnerId, KalturaSessionType::USER);
$client->setKs($ks);
$result = $client->media->upload('Web2Explained.flv');
print_r($result);

For info 'Web2Explained.flv' is a file on my (PHP) server in same directory as this script is running.

I don't quite understand what the parameter on the upload action should be. Should it be:
1) the form field name ( so referencing a file to upload from client terminal)
2) the path to the file on the (PHP) server, to be uploaded to Kaltura server
3) the binary data of the actual file

The API docs call it the fileName, but the type is given as file - so this to me implies that it should be the binary data, but the example that I've seen shows just using a filename (not the actual file data).

Any help much appreciated :-)

Thanks,
Alex

Joined: 01/04/2011
Points: 17

So with the parameter for the upload action, I've tried with putting the path to the file (on the PHP server) and I've tried using file_get_contents() to pass the file data, but neither of these produce anything other than the same formdata error.

Which leaves putting in the form fieldname, but I can't seem to get this working either.

Anyone have any clues for me as to where I'm going wrong?
Cheers,
Alex

Joined: 01/04/2011
Points: 17

After coming back to this again recently, I've not got any further with being able to upload using the API (as per my messages and code above).

Does anyone have an example php script with a working upload using the API?

Any help much appreciated,
Alex

Joined: 12/18/2010
Points: 29

I have upload working, but not using upload().

The upload() function expects an object, not a URL. And it further expects you have correctly constructed $_FILES. Even then, it gave me grief.

To get it working, I upload to a directory on the server, then call Kaltura to addFromUrl(), which needs a KalturaMediaEntry with the file name and media type fields filled in as the first parameter, and the URL where you uploaded it as the second parameter. In PHP, you must do a move_uploaded_file() on it first, to move it to your web-accessible dir, before calling addFromUrl().

This works perfectly for images, but I'm getting 404 errors uploading videos using the same code. I set the curl timeout to 600 seconds, so that's not it. You don't get much to go on:

2011-09-11 21:19:51 [127.0.0.1] [1866201788] [API] [kLog::log] NOTICE: curl_exec result [404]

I think the error is because Kaltura attempts to fetch it before it's there, but I haven't traced it all out yet. Any ideas?

Hope that first part helps, and if anyone has an answer for the latter part, I'm all ears.

Joined: 09/22/2011
Points: 6

I don't think upload takes an object. The example use from Kaltura passes a the file path as argument (http://www.kaltura.org/kalorg/kaltura-api-clients-sample-code/php/Sample...)

What Alex is missing is the addFromUploadedFile($entryObj, $result_from_upload)

So something like this:

$result_upload = $client->media->upload($media_path);
$result = $client->media->addFromUploadedFile($entryObj, $result_upload);

However, I'm also only getting the entry to show up on KMC and no file ends up being available (status remains in 'uploading' or 'converting' state).

I'm not sure what it is but I'll try doing the move_uploaded_file() before calling these functions...

FJ

Joined: 09/22/2011
Points: 6

The reason why I wan't getting the file data to actually be copied to the kaltura server from my api server was that I have the entry->type flag:

entry->type = KalturaEntryType::AUTOMATIC;

By not setting the entry type, things work fine.
Now I just use:

entry->mediaType = KalturaMediaType::VIDEO;
entry->sourceType = KalturaSourceType::FILE;

Hooray!

Joined: 12/18/2010
Points: 29

Re: my post above

Videos are working. Remember to change php.ini's upload_max_filesize to something large enough to handle what you're uploading.

It made the flavors.

Joined: 08/17/2011
Points: 82

how to use Simple Uploader Widget and other widgets ....we are new to kaltura