Ejemplo n.º 1
0
        public async Task <FileUploadResult> UploadFiles(UploadRequest request)
        {
            if (request.Files == null)
            {
                throw new ArgumentNullException(nameof(request.Files));
            }

            FileUploadResult uploadResult = await UploadAllFiles(request);

            return(uploadResult);
        }
Ejemplo n.º 2
0
        private async Task <FileUploadResult> UploadAllFiles(UploadRequest request)
        {
            var folder       = $"{_environment}/feed-{request.FeedId}";
            var uploadResult = new FileUploadResult();

            foreach (var file in request.Files)
            {
                if (file.FileType == FileType.Image)
                {
                    var result = await _client.UploadAsync(new ImageUploadParams
                    {
                        File           = new FileDescription(file.DataUrl),
                        Folder         = folder,
                        Transformation = new Transformation().Height(2000).Quality(60),
                        UploadPreset   = _uploadPreset
                    });

                    file.PublicId = result.PublicId;
                    uploadResult.UploadResults.Add(new FileUploadResult.UploadResult
                    {
                        Success = result.StatusCode == HttpStatusCode.OK,
                        File    = file
                    });
                }
                else
                {
                    var result = await _client.UploadAsync(new VideoUploadParams
                    {
                        File           = new FileDescription(file.DataUrl),
                        Folder         = folder,
                        Transformation = new Transformation().Height(2000).Quality(60),
                        UploadPreset   = _uploadPreset
                    });

                    file.PublicId = result.PublicId;
                    uploadResult.UploadResults.Add(new FileUploadResult.UploadResult
                    {
                        Success = result.StatusCode == HttpStatusCode.OK,
                        File    = file
                    });
                }
            }

            return(uploadResult);
        }