Parameters for deletion of resource from cloudinary
Inheritance: BaseParams
Ejemplo n.º 1
0
        public string DeletePhoto(string publicId)
        {
            var deleteParams = new CloudinaryDotNet.Actions.DeletionParams(publicId);
            var result       = _cloudinary.Destroy(deleteParams);

            return(result.Result == "ok" ? result.Result : null);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _repo.GetUser(userId);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("You cannot delete the main photo"));
            }


            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new CloudinaryDotNet.Actions.DeletionParams(photoFromRepo.PublicId);
                var result       = _cloudinary.Destroy(deleteParams);
                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }

                if (await _repo.SaveAll())
                {
                    return(Ok());
                }
            }

            if (photoFromRepo.PublicId != null)
            {
                _repo.Delete(photoFromRepo);
            }

            return(BadRequest("Failed to delete the photo"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Delete file from cloudinary
        /// </summary>
        /// <param name="parameters">Parameters for deletion of resource from cloudinary</param>
        /// <returns>Results of deletion</returns>
        public DeletionResult Destroy(DeletionParams parameters)
        {
            string uri = m_api.ApiUrlImgUpV.ResourceType(
                Api.GetCloudinaryParam<ResourceType>(parameters.ResourceType)).
                Action("destroy").BuildUrl();

            using (HttpWebResponse response = m_api.Call(HttpMethod.POST, uri, parameters.ToParamsDictionary(), null))
            {
                DeletionResult result = DeletionResult.Parse(response);
                return result;
            }
        }
Ejemplo n.º 4
0
 public void DeletePhoto(String publicId)
 {
     var deleteParam = new DeletionParams(publicId);
     Cloudinary.Destroy(deleteParam);
 }
Ejemplo n.º 5
0
        public void TestDestroyRaw()
        {
            RawUploadParams uploadParams = new RawUploadParams()
            {
                File = new FileDescription(m_testImagePath)
            };

            RawUploadResult uploadResult = m_cloudinary.Upload(uploadParams, "raw");

            Assert.NotNull(uploadResult);

            DeletionParams destroyParams = new DeletionParams(uploadResult.PublicId)
            {
                ResourceType = ResourceType.Raw
            };

            DeletionResult destroyResult = m_cloudinary.Destroy(destroyParams);

            Assert.AreEqual("ok", destroyResult.Result);
        }