Thanks for the pointers. I’m still having the same problem though I’m afraid so below is a snippet from the log file and the code the I am running.
The log file snippet may not necessarily be from the correct place but it does mention the property i am having problems with so I’ve included it. If you need a different part of the file please let me know.
Log file section
2015-10-23 12:57:00 [0.002290] [82.35.202.10] [1181352838] [3] [API] [KalturaFrontController->run] DEBUG: Params [Array
(
[advancedOptions:objectType] => KalturaEntryReplacementOptions
[apiVersion] => 3.2.0
[clientTag] => dotnet:15-05-14
[conversionProfileId] => 0
[entryId] => 0_vrb2bwsa
[format] => 2
[kalsig] => b8908ce2f038315de01966a7a385b71b
[ks] => Njc0NDljZjhmMWU3ZDRjYjQ5M2IwYWE3MWM0YmY5NDY0Y2NhODliMnwxMDQ7MTA0OzE0NDU2ODQyMTI7Mjs2MzU4MTE5ODIxMjM4NDMwODg7dGVzdFVzZXI7Ow==
[partnerId] => 104
[resource:localFilePath] => F:\Work\Code\Visual Studio 2013\Projects\TWMKaltura\TWMKaltura\SampleVideo.mp4
[resource:objectType] => KalturaServerFileResource
[service] => baseentry
[action] => updateContent
)
]
2015-10-23 12:57:00 [0.010892] [82.35.202.10] [1181352838] [4] [API] [KalturaDispatcher->dispatch] DEBUG: Dispatching service [baseentry], action [updatecontent], reqIndex [1] with params Array
(
[0] => 0_vrb2bwsa
[1] => KalturaServerFileResource Object
(
[localFilePath] => F:\Work\Code\Visual Studio 2013\Projects\TWMKaltura\TWMKaltura\SampleVideo.mp4
[relatedObjects] =>
)
[2] => 0
[3] => KalturaEntryReplacementOptions Object
(
[keepManualThumbnails] =>
[relatedObjects] =>
)
)
====================
Code
using System;
using System.Web;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using Kaltura;
namespace TWMKaltura
{
public partial class FileUpload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FileUploader fu = new FileUploader();
fu.ProcessRequest(HttpContext.Current);
}
//Routine to check filename for invalid chars
private static readonly Regex InvalidFileRegex = new Regex(string.Format("[{0}]", Regex.Escape(@"<>:""/\|?*")));
public static string SanitizeFileName(string fileName)
{
return InvalidFileRegex.Replace(fileName, string.Empty);
}
public class FileUploader : IHttpHandler
{
static KalturaConfiguration GetConfig()
{
KalturaConfiguration config = new KalturaConfiguration(PARTNER_ID);
config.ServiceUrl = SERVICE_URL;
return config;
}
//this function checks if a given flavor system name exist in the account.
static int? CheckIfFlavorExist(String name)
{
KalturaClient client = new KalturaClient(GetConfig());
string ks = client.GenerateSession(ADMIN_SECRET, USER_ID, KalturaSessionType.ADMIN, PARTNER_ID, 86400, "");
client.KS = ks;
//verify that the account we're testing has the new iPad flavor enabled on the default conversion profile
KalturaConversionProfile defaultProfile = client.ConversionProfileService.GetDefault();
KalturaConversionProfileAssetParamsFilter flavorsListFilter = new KalturaConversionProfileAssetParamsFilter();
flavorsListFilter.SystemNameEqual = name;
flavorsListFilter.ConversionProfileIdEqual = defaultProfile.Id;
KalturaConversionProfileAssetParamsListResponse list = client.ConversionProfileAssetParamsService.List(flavorsListFilter);
if (list.TotalCount > 0)
return list.Objects[0].AssetParamsId;
else
return null;
}
public void ProcessRequest(HttpContext context)
{
try
{
string fileName = HttpContext.Current.Request.QueryString["FileName"].ToString();
fileName = SanitizeFileName(fileName);
using (FileStream fs = File.Create(context.Server.MapPath("~") + @"\" + fileName))
{
Byte[] buffer = new Byte[32 * 1024];
int read = context.Request.GetBufferlessInputStream().Read(buffer, 0, buffer.Length);
while (read > 0)
{
fs.Write(buffer, 0, read);
read = context.Request.GetBufferlessInputStream().Read(buffer, 0, buffer.Length);
}
}
string objectid = HttpContext.Current.Request.QueryString["objectid"];
string objectTypeid = HttpContext.Current.Request.QueryString["objectTypeid"];
string prefix = HttpContext.Current.Request.QueryString["prefix"];
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Database"].ConnectionString);
// Get details saved already for this video which are then used
// when importing the video
SqlDataAdapter da = new SqlDataAdapter("Select * from tbl_D2_Object where objectid=" + objectid + " and objecttypeid=" + objectTypeid, conn);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
FileStream fileStream = new FileStream(context.Server.MapPath("~") + @"\" + fileName, FileMode.Open, FileAccess.Read);
KalturaClient client = new KalturaClient(GetConfig());
string ks = client.GenerateSession(ADMIN_SECRET, USER_ID, KalturaSessionType.ADMIN, PARTNER_ID, 86400, "");
client.KS = ks;
KalturaUploadToken uploadToken = client.UploadTokenService.Add();
client.UploadTokenService.Upload(uploadToken.Id, fileStream);
KalturaUploadedFileTokenResource mediaResource = new KalturaUploadedFileTokenResource();
mediaResource.Token = uploadToken.Id;
KalturaMediaEntry mediaEntry = new KalturaMediaEntry();
mediaEntry.Name = ds.Tables[0].Rows[0]["Synopsis"].ToString();
mediaEntry.ReferenceId = prefix + "-" + objectid;
mediaEntry.MediaType = KalturaMediaType.VIDEO;
mediaEntry = client.MediaService.Add(mediaEntry);
mediaEntry = client.MediaService.AddContent(mediaEntry.Id, mediaResource);
string videoid = mediaEntry.Id;
string thumbnail = mediaEntry.ThumbnailUrl;
int duration = mediaEntry.Duration;
string status = mediaEntry.Status.ToString();
while (status != "1")
{
context.Response.Write("Converting");
status = mediaEntry.Status.ToString();
}
conn.Open();
SqlDataAdapter da2 = new SqlDataAdapter("Select * from tbl_D2_ObjectExtras where objectid=" + objectid + " and objecttypeid=" + objectTypeid, conn);
DataSet ds2 = new DataSet();
da2.Fill(ds2);
if (ds2.Tables[0].Rows.Count > 0)
{
SqlCommand CMD = new SqlCommand("UPDATE tbl_D2_ObjectExtras SET Prefix='" + prefix + "', ObjectId =" + objectid + ", objectTypeId =" + objectTypeid + ", Filename = '" + videoid + "', Thumbnail = '" + thumbnail + "', Duration = " + duration + " WHERE Prefix = '" + prefix + "' AND ObjectID =" + objectid + " AND objectTypeId =" + objectTypeid, conn);
CMD.ExecuteNonQuery();
}
else
{
SqlCommand cmd = new SqlCommand("INSERT INTO tbl_D2_ObjectExtras (Prefix, ObjectID, PageNo, ObjectTypeID, Filename, Thumbnail, Duration) VALUES ('" + prefix + "'," + objectid + ",1," + objectTypeid + ",'" + videoid + "','" + thumbnail + "'," + duration + ")", conn);
cmd.ExecuteNonQuery();
}
// Set the status on the object table to offline
SqlCommand cmd2 = new SqlCommand("UPDATE tbl_D2_Object SET Status = 1 WHERE ObjectID = " + objectid + " AND ObjectTypeID = 16", conn);
cmd2.ExecuteNonQuery();
context.Response.Write("Success");
}
}
catch(Exception ex)
{
//context.Response.Write(ex.Message);
context.Response.Write("fail");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
}
================
Thanks,
Steve