// This function should be implemented as an async function while user get notification (signalR logic) // when everything is done and video can be played public Video UploadFile(IFormFile file) { try { string fileName = file.FileName.Replace(" ", ""); string videosFolder = Path.Combine(Directory.GetCurrentDirectory(), videoFolderName); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName); // Create video folder string videoFolderPath = Path.Combine(videosFolder, fileNameWithoutExtension); int ind = 0; while (Directory.Exists(videoFolderPath)) { ind++; videoFolderPath = videoFolderPath + "_" + ind; } Directory.CreateDirectory(videoFolderPath); string originalFilePath = Path.Combine(videoFolderPath, fileName); using (FileStream stream = new FileStream(originalFilePath, FileMode.Create)) { // Save file in videos folder file.CopyTo(stream); } // Create video metadate to store in DB Video video = new Video() { Name = fileName, VideoFolderPath = videoFolderPath, Created = DateTime.Now }; // Create thumbnails HandleThumbnails(originalFilePath, video); // Convert to HD: string hdFilePath = ScaleVideo(originalFilePath, hdResolution); if (!string.IsNullOrEmpty(hdFilePath)) { video.HdFilePath = hdFilePath; } //Create hls files string hlsFilePath = CreateHlsFiles(originalFilePath); if (!string.IsNullOrEmpty(hlsFilePath)) { video.HlsFilePath = hlsFilePath; } video.Id = dal.Insert(video); return(video); } catch (Exception ex) { //TODO: log error Console.WriteLine(ex.ToString()); throw; } }
public int InsertVideo(Video video) { return(dal.Insert(video)); }