/// <summary>
        /// Populate metadata fields with the given values. Existing values will be overwritten.
        ///
        /// Any metadata-value pairs given are merged with any existing metadata-value pairs
        /// (an empty value for an existing metadata field clears the value).
        /// </summary>
        /// <param name="parameters">Values to be applied to metadata fields of uploaded assets.</param>
        /// <returns>Parsed result of the operation.</returns>
        public MetadataUpdateResult UpdateMetadata(MetadataUpdateParams parameters)
        {
            var url = GetApiUrlV().
                      Add(Api.GetCloudinaryParam(parameters.ResourceType)).
                      Add(Constants.METADATA).
                      BuildUrl();
            var result = m_api.CallApi <MetadataUpdateResult>(HttpMethod.POST, url, parameters, null);

            return(result);
        }
Ejemplo n.º 2
0
        public void TestMetadataUpdateParamsDictionary()
        {
            var parameters = new MetadataUpdateParams
            {
                PublicIds = new List <string> {
                    "test_id_1", "test_id_2"
                }
            };

            parameters.Metadata.Add("metadata_color", "red");
            parameters.Metadata.Add("metadata_shape", "");

            Assert.DoesNotThrow(parameters.Check);
            var dictionary = parameters.ToParamsDictionary();

            Assert.AreEqual(parameters.Type, dictionary["type"]);
            Assert.AreEqual(parameters.PublicIds, dictionary["public_ids"]);
            Assert.AreEqual("metadata_color=red|metadata_shape", dictionary["metadata"]);
        }
        public void TestUpdateMetadata()
        {
            var uploadResult = m_cloudinary.Upload(new ImageUploadParams
            {
                File = new FileDescription(m_testImagePath),
            });
            var metadataExternalId = CreateMetadataField("metadata_update");

            var updateParams = new MetadataUpdateParams
            {
                PublicIds = new List <string> {
                    uploadResult.PublicId
                },
            };

            updateParams.Metadata.Add(metadataExternalId, "new value");

            var updateResult = m_cloudinary.UpdateMetadata(updateParams);

            Assert.NotNull(updateResult);
            Assert.AreEqual(HttpStatusCode.OK, updateResult.StatusCode, updateResult.Error?.Message);
            Assert.IsNotEmpty(updateResult.PublicIds);
        }
Ejemplo n.º 4
0
        public void TestMetadataUpdateParamsCheck()
        {
            var parameters = new MetadataUpdateParams();

            Assert.Throws <ArgumentException>(parameters.Check, "List of public ids should not be empty");
        }