示例#1
0
        public async void TestUpload()
        {
            var file = Path.Combine("data", "logo.png");
            var r    = await Cloudinary.UploadAsync(new ImageUploadParams()
            {
                PublicId = "testing1",
                File     = new FileDescription("logo.png", this.ReadFile(file)),
                Folder   = "test"
            });

            Assert.Equal("test/testing1", r.PublicId);
            Assert.Null(r.Error);

            var getResult = await Cloudinary.GetResourceAsync(new GetResourceParams("test/testing1"));

            Assert.Null(getResult.Error);
            Assert.Equal(getResult.PublicId, "test/testing1");

            var delPar = new DelResParams();

            delPar.PublicIds.Add("test/testing1");
            var delResult = await Cloudinary.DeleteResourcesAsync(delPar);

            Assert.Null(delResult.Error);

            getResult = await Cloudinary.GetResourceAsync(new GetResourceParams("test/testing1"));

            Assert.NotNull(getResult.Error);
        }
        public async Task <bool> DeleteFile(string fileName)
        {
            Guard.WhenArgument(
                fileName,
                GlobalConstants.FileNameRequiredExceptionMessage).IsNullOrWhiteSpace().Throw();

            var delParams = new DelResParams()
            {
                PublicIds = new List <string>()
                {
                    fileName
                },
                Invalidate = true
            };

            DelResResult delResult = null;

            try
            {
                delResult = await this.cloud.DeleteResourcesAsync(delParams);
            }
            catch (Exception)
            {
                // Log stuff
            }

            return(delResult.StatusCode == HttpStatusCode.OK);
        }
示例#3
0
        public static DelResResult DeleteResources(this Cloudinary cloudinary, params string[] publicIds)
        {
            var parameters = new DelResParams();

            parameters.PublicIds.AddRange(publicIds);
            return(cloudinary.DeleteResources(parameters));
        }
        public string DeleteProducts()
        {
            var AllProducts = repo.GetAll().ToList();

            string status = "No Products To Delete";

            foreach (var product in AllProducts)
            {
                if (product.quantityAvailable < 1)
                {
                    status = "Product To Delete Found";
                    var publicId = this.GetPublicId(product.productImageUrl);

                    var delParams = new DelResParams()
                    {
                        PublicIds = new List <string>()
                        {
                            publicId
                        },
                        Invalidate = true
                    };

                    var deleteresult = cloudinary.DeleteResources(delParams);

                    repo.Delete(product.Id);
                    status += product.prodCode + " - Deleted";
                }
                repo.Commit();
            }

            return(status);
        }
示例#5
0
        public DelResResult DeleteResources(params string[] publicIds)
        {
            DelResParams p = new DelResParams();

            p.PublicIds.AddRange(publicIds);
            return(DeleteResources(p));
        }
        public void TestDeleteResultDeleteCountProperty()
        {
            // should allow deleting resources by transformations
            var publicId = GetUniquePublicId();

            var transformations = new List <Transformation>
            {
                m_simpleTransformation,
                m_simpleTransformationAngle,
                m_explicitTransformation
            };

            var uploadParams = new ImageUploadParams()
            {
                File            = new FileDescription(m_testImagePath),
                PublicId        = publicId,
                Tags            = m_apiTag,
                EagerTransforms = transformations
            };

            m_cloudinary.Upload(uploadParams);

            var delParams = new DelResParams {
                Transformations = transformations
            };

            delParams.PublicIds.Add(publicId);

            DelResResult delResult = m_cloudinary.DeleteResources(delParams);

            Assert.IsNotNull(delResult.Deleted, delResult.Error?.Message);
            Assert.AreEqual(1, delResult.DeletedCounts.Count);
        }
        public async Task <IActionResult> DeleteUserByEmail(string email)
        {
            var response = new
            {
                status = 404,
                errors = new List <string>()
                {
                    "Account Not Found"
                }
            };

            var otherResponse = new
            {
                status = 401,
                errors = new List <string>()
                {
                    "Not Authorized"
                }
            };

            // Find this user by looking for the specific id
            var user = await _context.Users.FirstOrDefaultAsync(user => user.Email == email);

            if (user == null)
            {
                // There wasn't a user with that id so return a `404` not found
                return(NotFound(response));
            }

            var currentUser = await _context.Users.FindAsync(GetCurrentUserId());

            if (currentUser.Tier < 3)
            {
                return(Unauthorized(response));
            }

            //Caputes photos id's of the vehicle being deleted
            var photos = user.Media
                         .Where(photo => photo.PublicId != "")
                         .Select(photo => photo.PublicId).ToList();

            // Removes Media Files From Cloudinary
            var cloudinaryClient = new Cloudinary(new Account(CLOUDINARY_CLOUD_NAME, CLOUDINARY_API_KEY, CLOUDINARY_API_SECRET));
            var delResParams     = new DelResParams()
            {
                PublicIds = new List <string>(photos)
            };

            cloudinaryClient.DeleteResources(delResParams);

            // Tell the database we want to remove this record
            _context.Users.Remove(user);

            // Tell the database to perform the deletion
            await _context.SaveChangesAsync();

            // Return a copy of the deleted data
            return(Ok(user));
        }
示例#8
0
        public async Task <ActionResult> Delete(IFormCollection collection)
        {
            var id        = Convert.ToInt64(collection["ImageId"]);
            var image     = _databaseConnection.Images.Find(id);
            var imageFile = image.FilePath.Replace("/cloudmab/image/upload/v1517001994/", "");


            //upload image via Cloudinary API Call
            var account = new Account(
                new AppConfig().CloudinaryAccoutnName,
                new AppConfig().CloudinaryApiKey,
                new AppConfig().CloudinaryApiSecret);

            var cloudinary = new Cloudinary(account);
            var delParams  = new DelResParams
            {
                PublicIds = new List <string> {
                    imageFile
                },
                Invalidate = true
            };
            await cloudinary.DeleteResourcesAsync(delParams);

            var tags = _databaseConnection.ImageTags.Where(n => n.ImageId == image.ImageId);

            foreach (var item in tags)
            {
                _databaseConnection.ImageTags.RemoveRange(item);
            }
            var imageActions = _databaseConnection.ImageActions.Where(n => n.ImageId == image.ImageId);

            foreach (var item in imageActions)
            {
                _databaseConnection.ImageActions.RemoveRange(item);
            }
            var imageComments = _databaseConnection.ImageComments.Where(n => n.ImageId == image.ImageId);

            foreach (var item in imageComments)
            {
                _databaseConnection.ImageComments.RemoveRange(item);
            }
            var imageReports = _databaseConnection.ImageReports.Where(n => n.ImageId == image.ImageId);

            foreach (var item in imageReports)
            {
                _databaseConnection.ImageReports.RemoveRange(item);
            }

            _databaseConnection.Images.Remove(image);
            _databaseConnection.SaveChanges();


            //display notification
            TempData["display"]          = "You have successfully deleted the Image from your Library!";
            TempData["notificationtype"] = NotificationType.Success.ToString();
            return(RedirectToAction("Index"));
        }
示例#9
0
        public DelResResult DeleteResourcesByPrefix(string prefix)
        {
            DelResParams p = new DelResParams()
            {
                Prefix = prefix
            };

            return(DeleteResources(p));
        }
示例#10
0
        public DelResResult DeleteResourcesByTag(string tag)
        {
            DelResParams p = new DelResParams()
            {
                Tag = tag
            };

            return(DeleteResources(p));
        }
示例#11
0
        public DelResResult DeleteAllResources(bool keepOriginal, string nextCursor)
        {
            DelResParams p = new DelResParams()
            {
                All = true, KeepOriginal = keepOriginal, NextCursor = nextCursor
            };

            return(DeleteResources(p));
        }
示例#12
0
        public DelResResult DeleteAllResources()
        {
            DelResParams p = new DelResParams()
            {
                All = true
            };

            return(DeleteResources(p));
        }
示例#13
0
        public DelResResult DeleteResourcesByTag(string tag, bool keepOriginal, string nextCursor)
        {
            DelResParams p = new DelResParams()
            {
                Tag = tag, KeepOriginal = keepOriginal, NextCursor = nextCursor
            };

            return(DeleteResources(p));
        }
示例#14
0
        public DelResResult DeleteResourcesByPrefix(string prefix, bool keepOriginal, string nextCursor)
        {
            DelResParams p = new DelResParams()
            {
                Prefix = prefix, KeepOriginal = keepOriginal, NextCursor = nextCursor
            };

            return(DeleteResources(p));
        }
示例#15
0
        public DelResResult DeleteResources(ResourceType type, params string[] publicIds)
        {
            DelResParams p = new DelResParams()
            {
                ResourceType = type
            };

            p.PublicIds.AddRange(publicIds);
            return(DeleteResources(p));
        }
        public async Task <DelResResult> DeleteImage(string publicId)
        {
            var delParams = new DelResParams {
                PublicIds = new List <string> {
                    publicId
                }, Invalidate = true
            };

            return(_cloudinary.DeleteResources(delParams));
        }
        public async Task DeleteImages(params string[] publicIds)
        {
            var delParams = new DelResParams
            {
                PublicIds  = publicIds.ToList(),
                Invalidate = true
            };

            await cloudinary.DeleteResourcesAsync(delParams);
        }
示例#18
0
        public async Task DeleteBeats(params string[] publicIds)
        {
            var delParams = new DelResParams
            {
                PublicIds    = publicIds.ToList(),
                Invalidate   = true,
                ResourceType = ResourceType.Video,
            };

            await this.cloudinary.DeleteResourcesAsync(delParams);
        }
示例#19
0
        public void DeletePictureAsync(string fileName)
        {
            var delResParams = new DelResParams()
            {
                PublicIds = new List <string> {
                    fileName
                }
            };

            var delResult = _cloudinaryUtility.DeleteResources(delResParams);
        }
示例#20
0
        public async Task <IActionResult> DeleteAddress(int id)
        {
            // Find this vehicle by looking for the specific id
            var address = await _context.Addresses
                          .FirstOrDefaultAsync(dealer => dealer.Id == id);

            if (address == null)
            {
                // There wasn't a vehicle with that id so return a `404` not found
                return(NotFound());
            }

            // Find the user information of the user that called a delete request
            var user = await _context.Users.FindAsync(GetCurrentUserId());

            if (user.Tier < 3)
            {
                // Make a custom error response
                var response = new
                {
                    status = 401,
                    errors = new List <string>()
                    {
                        "Not Authorized"
                    }
                };

                // Return our error with the custom response
                return(Unauthorized(response));
            }

            // Caputes photos id's of the vehicle being deleted
            var photos = address.Media
                         .Where(photo => photo.PublicId != "")
                         .Select(photo => photo.PublicId).ToList();

            // Removes Media Files From Cloudinary
            var cloudinaryClient = new Cloudinary(new Account(CLOUDINARY_CLOUD_NAME, CLOUDINARY_API_KEY, CLOUDINARY_API_SECRET));
            var delResParams     = new DelResParams()
            {
                PublicIds = new List <string>(photos)
            };

            cloudinaryClient.DeleteResources(delResParams);

            // Tell the database we want to remove this record
            _context.Addresses.Remove(address);

            // Tell the database to perform the deletion
            await _context.SaveChangesAsync();

            // Return a copy of the deleted data
            return(Ok(address));
        }
示例#21
0
        public async Task <IActionResult> DeleteDeveloper([FromRoute] int?id, [FromForm] int formId)
        {
            if (id != formId)
            {
                return(BadRequest());
            }

            var devForDeletion = await _repo.GetDeveloper(id);

            if (devForDeletion == null)
            {
                return(NotFound());
            }

            List <string> photosForDeletion = new List <string>();

            if (devForDeletion.PhotoId != null)
            {
                photosForDeletion.Add(devForDeletion.PhotoId);
            }

            if (devForDeletion.Games.ToList().Count > 0)
            {
                foreach (Game game in devForDeletion.Games)
                {
                    if (!String.IsNullOrEmpty(game.PhotoId))
                    {
                        photosForDeletion.Add(game.PhotoId);
                    }
                }
            }

            if (photosForDeletion.Count > 0)
            {
                var delParams = new DelResParams()
                {
                    PublicIds = photosForDeletion
                };

                _cloudinary.DeleteResources(delParams);
            }

            _repo.Delete(devForDeletion);

            if (await _repo.SaveAll())
            {
                SetMessage("info", "Developer deleted");
                return(RedirectToAction(nameof(Index)));
            }

            SetMessage("danger", "Something went wrong. Could not complete request");
            return(RedirectToAction(nameof(Index)));
        }
示例#22
0
        public void DeleteResource(string publicId)
        {
            var delParams = new DelResParams()
            {
                PublicIds = new List <string>()
                {
                    publicId
                }, Invalidate = true
            };

            _cloudinary.DeleteResources(delParams);
        }
 public async Task DeleteAsync(string publicId)
 {
     var delParams = new DelResParams
     {
         ResourceType = ResourceType.Image,
         PublicIds    = new List <string>
         {
             publicId
         }
     };
     await cloudinary.DeleteResourcesAsync(delParams);
 }
示例#24
0
        public async Task <DelResResult> DeleteResourcesAsync(DelResParams parameters)
        {
            var url = Api.ApiUrlV.Add("resources").Add(Api.GetCloudinaryParam(parameters.ResourceType));

            using (
                var response = await Api.CallAsync(HttpMethod.Delete,
                                                   new UrlBuilder((string.IsNullOrEmpty(parameters.Tag) ? url.Add(parameters.Type) : url.Add("tags").Add(parameters.Tag)).BuildUrl(), parameters.ToParamsDictionary()).ToString(), null,
                                                   null, null))
            {
                return(await DelResResult.Parse(response));
            }
        }
示例#25
0
        public static void DeleteImage(Cloudinary cloudinary, string name)
        {
            var delParams = new DelResParams()
            {
                PublicIds = new List <string>()
                {
                    name
                },
                Invalidate = true,
            };

            cloudinary.DeleteResources(delParams);
        }
示例#26
0
    public async Task <DelResResult> DeleteResource(string publicId)
    {
        var delParams = new DelResParams()
        {
            PublicIds = new List <string>()
            {
                publicId
            },
            Invalidate = true
        };

        return(await _cloudinary.DeleteResourcesAsync(delParams));
    }
        public async Task DeleteImage(Cloudinary cloudinary, string name)
        {
            var delParams = new DelResParams()
            {
                PublicIds = new List <string>()
                {
                    name
                },
                Invalidate = true,
            };

            await cloudinary.DeleteResourcesAsync(delParams);
        }
示例#28
0
        public void DeleteCloudinaryRecipeImage(string imageName)
        {
            CloudinaryDotNet.Cloudinary cloudinaryDelete = new CloudinaryDotNet.Cloudinary(cloudinaryAccount);

            var delParams = new DelResParams()
            {
                PublicIds = new List <string>()
                {
                    Path.GetFileNameWithoutExtension(imageName)
                },
                Invalidate = true
            };
            DelResResult result = cloudinaryDelete.DeleteResources(delParams);
        }
示例#29
0
        /// <summary>
        /// Delete image from cloudinary
        /// </summary>
        /// <param name="name"></param>
        public void DeleteImage(string name)
        {
            var delParams = new DelResParams()
            {
                PublicIds = new List <string>()
                {
                    name
                },
                Invalidate   = true,
                ResourceType = ResourceType.Image
            };

            this.cloudinary.DeleteResources(delParams);
        }
示例#30
0
        private static void DeleteCloudinaryProfileImage(string username, string applicationName)
        {
            Cloudinary cloudinaryDelete = new Cloudinary(cloudinaryAccount);
            string     profileImageURL  = String.Format(@"{0}/{1}/{2}", cloudinaryAccountsFolder, applicationName, username);

            var delParams = new DelResParams()
            {
                PublicIds = new List <string>()
                {
                    profileImageURL
                },
                Invalidate = true
            };
            DelResResult result = cloudinaryDelete.DeleteResources(delParams);
        }