Ejemplo n.º 1
0
        private Stream UploadVideo()
        {
            var  file        = HttpContext.Current.Request.Files[0];
            var  fileStream  = file.InputStream;
            var  contentType = file.ContentType;
            var  filename    = file.FileName;
            long contentLength;

            byte[] data;
            using (var memoryStream = new MemoryStream())
            {
                fileStream.Position = 0;
                fileStream.CopyTo(memoryStream);
                contentLength = memoryStream.Length;
                data          = memoryStream.ToArray();
            }

            var newVideoRequest = new NewVideoRequest
            {
                Data          = data,
                ContentLength = contentLength,
                Title         = Path.GetFileNameWithoutExtension(filename),
                VideoPath     = filename,
                ContentType   = contentType
            };

            var response = _provider.VippyClient.PutVideo(newVideoRequest).Result;

            return(new MemoryStream());
        }
        public async Task <ActionResult> UploadVideo([FromForm] Models.Requests.NewVideoRequest request)
        {
            try
            {
                _newVideoValidator.ValidateAndThrow(request);
            }
            catch (ValidationException e)
            {
                return(BadRequest(e.Errors));
            }
            var newVideoRequest = new NewVideoRequest(request.VideoFile, request.VideoPreview, request.Description, request.Name, int.Parse(User.Id()), _env.WebRootPath);
            await _newVideoUseCase.Handle(newVideoRequest, _newVideoPresenter);

            return(_newVideoPresenter.ContentResult);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Used to upload new video.
        /// Vippy endpoint: PUT http://rest.vippy.co/video
        /// </summary>
        /// <param name="newVideoRequest"><see cref="NewVideoRequest"/></param>
        /// <returns>Video <see cref="Video"/></returns>
        // TODO: create strongly typed return type
        public async Task <dynamic> PutVideo(NewVideoRequest newVideoRequest)
        {
            var client = this.GetHttpClient();

            var dataContent = new ByteArrayContent(newVideoRequest.Data);

            dataContent.Headers.ContentType = MediaTypeHeaderValue.Parse(newVideoRequest.ContentType);
            client.DefaultRequestHeaders.Add("x-vpy-video", newVideoRequest.VideoPath);
            client.DefaultRequestHeaders.Add("x-vpy-title", newVideoRequest.Title);
            client.DefaultRequestHeaders.Authorization = this.GenerateAuthorizationHeader(client, dataContent.Headers);

            var response = await client.PutAsync("/video", dataContent).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();
            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <dynamic>(responseContent));
        }
Ejemplo n.º 4
0
        public async Task <bool> Handle(NewVideoRequest request, IOutputPort <NewVideoResponse> outputPort)
        {
            if (_userRepository.FindById(request.UserId) == null)
            {
                outputPort.Handle(new NewVideoResponse(new[] { new Error(404, "user not found") }));
                return(false);
            }
            if (_channelRepository.FindByUserId(request.UserId) == null)
            {
                outputPort.Handle(new NewVideoResponse(new[] { new Error(404, "you must have to create channel") }));
                return(false);
            }

            UploadedFileDto videoInfo = await _uploadService.UploadFile(request.VideoFile, request.WebRootPath);

            UploadedFileDto previewInfo = await _uploadService.UploadFile(request.VideoPreview, request.WebRootPath);

            UploadedFileDto uploadedVideo   = _uploadedFileRepository.Create(videoInfo);
            UploadedFileDto uploadedPreview = _uploadedFileRepository.Create(previewInfo);

            previewInfo.Id = uploadedPreview.Id;

            ImageDto videoPreview = _imageRepository.Create(new ImageDto()
            {
                UserId = request.UserId
            }, request.WebRootPath, previewInfo);
            var video = new VideoDto()
            {
                Description    = request.Description,
                Name           = request.Name,
                Views          = 0,
                Likes          = 0,
                Dislikes       = 0,
                PreviewImageId = videoPreview.Id,
                UserId         = request.UserId,
                UploadedFileId = uploadedVideo.Id,
            };
            VideoDto createdVideo = _videoRepository.Create(video);

            outputPort.Handle(new NewVideoResponse(createdVideo));
            return(true);
        }