Exemplo n.º 1
0
        public static ImageUploadResult UploadFile(IFormFile image)
        {
            var stream       = image.OpenReadStream();
            var uploadParams = new ImageUploadParams()
            {
                File = new FileDescription(image.FileName, stream)
            };
            Cloudinary cloudinary   = CloudAccount.Cloud();
            var        uploadResult = cloudinary.Upload(uploadParams);

            stream.Close();
            return(uploadResult);
        }
Exemplo n.º 2
0
        public static Collection CollectionProcess(CollectionAction collection)
        {
            var uploadResult = collection.Image != null?UploadFile(collection.Image) : null;

            if (uploadResult != null)
            {
                CloudAccount.DeleteFile(collection.ImageCloudId);
            }
            collectionResult = new Collection
            {
                Id          = collection.Id ?? Guid.NewGuid().ToString(),
                UserId      = collection.UserId,
                Title       = collection.Title,
                Description = collection.Description,
                Topic       = collection.Topic,
                ImgUrl      = collection.Image != null?GetImageCloudUrl(uploadResult, collection.Image.FileName) : collection.ImgUrl,
                                  ImageCloudId = collection.Image != null ? uploadResult.PublicId : collection.ImageCloudId
            };
            return(collectionResult);
        }