Пример #1
0
        public async Task <IActionResult> Index(VideoUploadViewModel videoUploadViewModel)
        {
            if (_authContext.User != null)
            {
                videoUploadViewModel.Video.UserId = _authContext.User.User.Id;

                if (!_tokenService.CheckIsTokenValid(videoUploadViewModel.Video.TokenUniqueId, 1))
                {
                    videoUploadViewModel.Video.DeveloperMessage = "Token is not valid";
                }
                var uploads = Path.Combine(_appEnvironment.WebRootPath, "Uploads\\Videos");
                var files   = HttpContext.Request.Form.Files;
                foreach (var file in files)
                {
                    if (file != null && file.Length > 0)
                    {
                        if (file.Length > 0)
                        {
                            var fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName);
                            using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                            {
                                await file.CopyToAsync(fileStream);

                                videoUploadViewModel.Video.VideoPath = fileName;
                            }
                        }
                    }
                }

                var thumblineName = Path.ChangeExtension(videoUploadViewModel.Video.VideoPath, "jpg");
                CreateAndSaveVideoThumbnail(videoUploadViewModel.Video.VideoPath, Path.Combine(uploads, thumblineName));
                videoUploadViewModel.Video.VideoThumblinePath = thumblineName;
                _videoService.UploadVideos(videoUploadViewModel);
            }

            return(await Task.Run(() => Index()));
        }