protected virtual Video CreateVideo(Item accountItem, VideoToUpload video) { var authenticator = new OoyalaAthenticator(accountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); return(context.Create <VideoToUpload, Video>("upload_video_create", video).Data); }
protected override object UploadInternal(NameValueCollection parameters, byte[] fileBytes, Item accountItem) { try { var fileName = this.GetFileName(parameters); string name = Path.GetFileNameWithoutExtension(fileName); var videoToUpload = new VideoToUpload { Name = name, ShortDescription = name, StartDate = ((long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString(CultureInfo.InvariantCulture) }; var authenticator = new BrightcoveAthenticator(accountItem); var updateData = new PostData("create_video", authenticator, "video", videoToUpload); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); IRestRequest restRequest = context.CreateRequest <PostData, ResultData <string> >(EntityActionType.Create, "update_data", updateData); restRequest.AddFile(name, fileBytes, fileName); restRequest.Timeout = 86400000; // 24h var data = context.GetResponse <ResultData <string> >(restRequest).Data; if (data != null && !string.IsNullOrEmpty(data.Result)) { return(new Video { Id = data.Result, Name = name }); } return(null); } catch (Exception ex) { LogHelper.Error("Brightcove Upload is failed", this, ex); return(null); } }
protected override object UploadInternal(NameValueCollection parameters, byte[] fileBytes, Item accountItem) { string fileName = this.GetFileName(parameters); var videoToUpload = new VideoToUpload { AssetType = "video", ChunkSize = MainUtil.GetLong(this.ChunkSize, 5000000), FileSize = fileBytes.LongLength, FileName = fileName, Name = Path.GetFileNameWithoutExtension(fileName), PostProcessingStatus = this.PostProcessingStatus }; Video video = this.CreateVideo(accountItem, videoToUpload); if (video != null) { try { var sended = this.SendContent(parameters, fileBytes, accountItem, video); if (sended) { this.MarkAs(accountItem, video, "uploaded"); video.Status = "processing"; return(video); } this.DeleteVideo(accountItem, video); return(new CanceledVideo()); } catch (Exception) { this.UpdateStatus(Guid.Empty, this.GetFileId(parameters), accountItem.ID.Guid, 0, "Uploading process failed. Please read logs for more details!"); this.MarkAs(accountItem, video, "failed"); } } return(null); }