public async Task <IActionResult> AddVideo([FromForm] DocumentForCreationResponse documentForCreationResponse, int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var asset = await _service.AddVideoAsync(documentForCreationResponse, id);

            return(Ok(asset));
        }
Example #2
0
        public async Task <DocumentForCreationResponse> AddVideoAsync(DocumentForCreationResponse documentForCreationResponse, int id)
        {
            var file         = documentForCreationResponse.File;
            var uploadResult = new VideoUploadResult();

            if (file.Length > 0)
            {
                using (var stream = file.OpenReadStream())
                {
                    var uploadParams = new VideoUploadParams()
                    {
                        File = new FileDescription(file.Name, stream)
                    };

                    uploadResult = _cloudinary.Upload(uploadParams);
                }
            }

            documentForCreationResponse.Url      = uploadResult.Uri.ToString();
            documentForCreationResponse.PublicId = uploadResult.PublicId;
            documentForCreationResponse.Name     = documentForCreationResponse.File.FileName;
            documentForCreationResponse.Type     = documentForCreationResponse.File.ContentType;
            documentForCreationResponse.UserId   = id;

            var   assetForReturn = documentForCreationResponse;
            Asset asset          = new Asset()
            {
                Name     = documentForCreationResponse.Name,
                Type     = documentForCreationResponse.Type,
                Url      = documentForCreationResponse.Url,
                PublicId = documentForCreationResponse.PublicId,
                UserId   = documentForCreationResponse.UserId
            };

            await _repository.AddImage(asset);

            return(assetForReturn);
        }