We seeem to have an issue uploading files larger than 120mb

Hi,

The title pretty much says it all really! We have code that is working correctly and reliably for files up to approx. 120mb but anything bigger is failing. The statement that is failing is:

UploadTokenService.Upload(uploadToken.Id, fileStream);

and it generates a “System.OutOfMemoryException” error.

Pasted below is the full code for the method that is running:

`public void ProcessRequest(HttpContext context)
{

            setupKaltura(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;

                    string status = mediaEntry.Status.ToString();
                    int duration = mediaEntry.Duration;
                    
                    //int duration = 0;

                    while (status != "1")
                    {
                        client.StartMultiRequest();
                        client.SessionService.Start(ADMIN_SECRET, "", KalturaSessionType.ADMIN, PARTNER_ID, 86400);
                        KalturaMediaEntry mediaEntry2 = client.MediaService.Get(videoid);

                        status = mediaEntry2.Status.ToString();
                        duration = mediaEntry2.Duration;
                    }


                    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");
            }
        }`

Many thanks,

Steve