public async Task <object> UploadVideo(IEnumerable <IFormFile> files, [FromForm] string date, [FromForm] bool isPublic) { var videoList = new List <VideoModel>(); foreach (var file in files) { try { var videoDate = string.IsNullOrEmpty(date) ? DateTime.Now : DateTime.ParseExact(date, "yyyyMMdd", null); var fileName = $"{videoDate.ToString("yyyyMMdd")}_{Guid.NewGuid().ToString()}.mp4"; var video = new VideoModel() { FileName = fileName, Date = videoDate, IsPublic = isPublic, Owner = User.Identity.Name }; using (var stream = file.OpenReadStream()) { video.Contents = new byte[stream.Length]; await stream.ReadAsync(video.Contents, 0, video.Contents.Length); stream.Seek(0, SeekOrigin.Begin); video.ThumbContents = await VideoUtil.CreateThumbnail(stream); } videoList.Add(video); } catch { } } return(new MessageDataResult(await VideosService.SaveItems(videoList), "Upload Video")); }
public async Task <IActionResult> GetVideo(string name, bool thumb = true) { if (thumb) { var bytes = (await VideosService.GetItemThumbContents(name)).First; if (bytes == null) { bytes = (await VideosService.GetItemContents(name)).First; if (bytes != null) { bytes = await VideoUtil.CreateThumbnail(bytes); await VideosService.UpdateItemThumbContents(name, bytes); } } return(File(bytes, "image/jpeg")); } else { var bytes = (await VideosService.GetItemContents(name)).First; return(File(bytes, "video/mp4")); } }