public async Task <UploadVideoResponseMessage> Handle(UploadVideoRequestMessage request, CancellationToken cancellationToken)
        {
            var validationResult = _validator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(new UploadVideoResponseMessage(validationResult));
            }

            if (!_fileExtension.Validate(request.Data))
            {
                validationResult.Errors.Add(new ValidationFailure("formatting", @"Format not supported"));
                return(new UploadVideoResponseMessage(validationResult));
            }

            var video = await _repository.GetByIdAsync <Video>(request.VideoId);

            if (video == null)
            {
                validationResult.Errors.Add(new ValidationFailure("not exist", "video not exist"));
                return(new UploadVideoResponseMessage(validationResult));
            }

            var uri = await _videoFileStorage.UploadVideo(request.Data);

            video.LinkedFile = new VideoFile()
            {
                Name    = request.VideoName,
                Uri     = uri,
                Version = string.Empty
            };
            await _repository.UpdateAsync(video);

            return(new UploadVideoResponseMessage(validationResult, request.VideoId, uri));
        }
        public async Task <string> Upload(byte[] data)
        {
            if (!_fileExtension.Validate(data))
            {
                throw new BadImageFormatException();
            }

            var format = _fileExtension.GetFormat(data);

            CreateDefaultDirectoryIfNotExist();

            string generatedName = $"{Guid.NewGuid()}.{format}";
            string filepath      = $"{_storagePath}/{generatedName}";

            using (FileStream stream = new FileStream(filepath, FileMode.Create))
            {
                stream.Seek(0, SeekOrigin.End);
                await stream.WriteAsync(data, 0, data.Length);
            }

            return(filepath);
        }