I’m having a trouble with the videos uploading. I’m using the latest version of Kaltura C# API. The problem occurs on the request.GetResponse() into KalturaClientBase’s “DoQueue” method, after loading all bytes of the file into the request.
The error message is “WebException was unhandled. The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.”.
This is weird because before the upload the system makes the media entry and gets the uploadToken id. Sometimes I pause the execution before do the request.GetResponse by a minute and half and then I continue it, the process works fine.
I made a class named “KalturaHelper” where I do the upload process. The code is below:
[...]
_config = new KalturaConfiguration(PARTNER_ID);
_config.ServiceUrl = SERVICE_URL;
//INSTANCE THE CLIENT AND MAKES A SESSION
_client = new KalturaClient(_config);
_ks = _client.GenerateSession(ADMIN_SECRET, USER_ID, KalturaSessionType.ADMIN, PARTNER_ID, SESSION_DURATION_MS, "");
_client.KS = _ks;
//MAKES A NEW MEDIA ENTRY
Console.WriteLine("\tCreating new media entry...");
KalturaMediaEntry mediaEntry = new KalturaMediaEntry();
mediaEntry.Name = "Media Entry Using C#";
mediaEntry.MediaType = KalturaMediaType.VIDEO;
mediaEntry = _client.MediaService.Add(mediaEntry);
Console.WriteLine("\tOK");
//UPLOADS THE FILE
Console.WriteLine("\tLoading file stream...");
FileStream fileStream = new FileStream("DemoVideo.flv", FileMode.Open, FileAccess.Read);
Console.WriteLine("\tUploading video...");
KalturaUploadToken uploadToken = _client.UploadTokenService.Add();
_client.UploadTokenService.Upload(uploadToken.Id, fileStream);
Console.WriteLine("\tOK");
//LINKING MEDIA ENTRY TO THE FILE
Console.WriteLine("\tAttaching new media entry to video...");
KalturaUploadedFileTokenResource mediaResource = new KalturaUploadedFileTokenResource();
mediaResource.Token = uploadToken.Id;
mediaEntry = _client.MediaService.AddContent(mediaEntry.Id, mediaResource);
Console.WriteLine("\tOK");
As you can see, it call the _client.UploadTokenService.Upload() method. Here breaks the execution. It throws me an error at “DoQueue” method into the KalturaClientBase.cs, more precisely on the “using” line:
[...]
// Add proxy information if required
createProxy(request, _Config);
if (kfiles.Count > 0)
{
this.PostMultiPartWithFiles(request, kparams, kfiles);
}
else
{
this.PostUrlEncodedParams(request, kparams);
}
// get the response
using (WebResponse response = request.GetResponse())
{
Encoding enc = System.Text.Encoding.UTF8;
StreamReader responseStream = new StreamReader(response.GetResponseStream(), enc);
string responseString = responseStream.ReadToEnd();
this._ResponseHeaders = response.Headers;
string serverName = null;
string serverSession = null;
for (int i = 0; i < this._ResponseHeaders.Count; ++i)
{
[...]
As in the request the system will send files, PostMultiPartWithFiles is executed, so in the request are the bytes of the file to upload.
Can’t see anything wrong with your code in an overview.
However, I work exclusively on Linux and cannot properly test this. I asked my colleagues to take a look and will let you know.