Parameters of upload preset.
Inheritance: BaseParams
コード例 #1
0
        /// <summary>
        /// Creates the upload preset.
        /// Upload presets allow you to define the default behavior for your uploads, instead of receiving these as parameters during the upload request itself. Upload presets have precedence over client-side upload parameters.
        /// </summary>
        /// <param name="parameters">Parameters of the upload preset.</param>
        /// <returns></returns>
        public UploadPresetResult CreateUploadPreset(UploadPresetParams parameters)
        {
            UrlBuilder urlBuilder = new UrlBuilder(
                m_api.ApiUrlV.
                Add("upload_presets").
                BuildUrl(),
                parameters.ToParamsDictionary());

            using (HttpWebResponse response = m_api.Call(HttpMethod.POST, urlBuilder.ToString(), null, null))
            {
                return UploadPresetResult.Parse(response);
            }
        }
コード例 #2
0
        /// <summary>
        /// Updates the upload preset.
        /// Every update overwrites all the preset settings.
        /// </summary>
        /// <param name="parameters">New parameters for upload preset.</param>
        /// <returns></returns>
        public UploadPresetResult UpdateUploadPreset(UploadPresetParams parameters)
        {
            var @params = parameters.ToParamsDictionary();
            @params.Remove("name");

            UrlBuilder urlBuilder = new UrlBuilder(
                m_api.ApiUrlV
                .Add("upload_presets")
                .Add(parameters.Name)
                .BuildUrl(),
                @params);

            using (HttpWebResponse response = m_api.Call(HttpMethod.PUT, urlBuilder.ToString(), null, null))
            {
                return UploadPresetResult.Parse(response);
            }
        }
コード例 #3
0
        public void TestGetUploadPreset()
        {
            // should allow getting a single upload_preset

            var tags = new string[] { "a", "b", "c" };

            var @params = new UploadPresetParams()
            {
                Tags = String.Join(",", tags),
                Context = new StringDictionary("a=b", "c=d"),
                Transformation = new Transformation().Width(100).Crop("scale"),
                EagerTransforms = new List<object>() { new Transformation().X(100) },
                FaceCoordinates = "1,2,3,4",
                Unsigned = true,
                Folder = "folder",
                AllowedFormats = new string[] { "jpg", "pdf" }
            };

            var creationResult = m_cloudinary.CreateUploadPreset(@params);

            var preset = m_cloudinary.GetUploadPreset(creationResult.Name);

            Assert.AreEqual(creationResult.Name, preset.Name);
            Assert.AreEqual(true, preset.Unsigned);
            Assert.AreEqual("folder", preset.Settings.Folder);
            Assert.AreEqual("100", preset.Settings.Transformation[0]["width"].ToString());
            Assert.AreEqual("scale", preset.Settings.Transformation[0]["crop"].ToString());

            m_cloudinary.DeleteUploadPreset(preset.Name);
        }
コード例 #4
0
        public void TestUpdateUploadPreset()
        {
            // should allow updating upload presets

            var presetToCreate = new UploadPresetParams()
            {
                Folder = "folder",
                Context = new StringDictionary("a=b", "b=c"),
                Transformation = new Transformation().X(100),
                EagerTransforms = new List<object>() { new Transformation().X(100).Y(100), "w_50" },
                AllowedFormats = new string[] { "jpg", "png" },
                Tags = "a,b,c",
                FaceCoordinates = "1,2,3,4"
            };

            var presetName = m_cloudinary.CreateUploadPreset(presetToCreate).Name;

            var preset = m_cloudinary.GetUploadPreset(presetName);

            var presetToUpdate = new UploadPresetParams(preset);

            presetToUpdate.Colors = true;
            presetToUpdate.Unsigned = true;
            presetToUpdate.DisallowPublicId = true;

            var result = m_cloudinary.UpdateUploadPreset(presetToUpdate);

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
            Assert.AreEqual("updated", result.Message);

            preset = m_cloudinary.GetUploadPreset(presetName);

            Assert.AreEqual(presetName, preset.Name);
            Assert.AreEqual(true, preset.Unsigned);

            // TODO: compare settings of preset and presetToUpdate

            m_cloudinary.DeleteUploadPreset(preset.Name);
        }
コード例 #5
0
        public void TestListUploadPresets()
        {
            // should allow creating and listing upload_presets

            var preset = new UploadPresetParams()
            {
                Name = "api_test_upload_preset",
                Folder = "folder",
                DisallowPublicId = true,
                Unsigned = true,
                AllowedFormats = new string[] { "jpg", "bmp" }
            };

            var result = m_cloudinary.CreateUploadPreset(preset);

            preset = new UploadPresetParams()
            {
                Name = "api_test_upload_preset2",
                Folder = "folder2",
                Tags = "a,b,c",
                Context = new StringDictionary("a=b", "c=d"),
                Transformation = new Transformation().Width(100).Crop("scale"),
                EagerTransforms = new List<object>() { new Transformation().X(100) },
                FaceCoordinates = "1,2,3,4"
            };

            result = m_cloudinary.CreateUploadPreset(preset);

            var presets = m_cloudinary.ListUploadPresets();

            Assert.AreEqual(presets.Presets[0].Name, "api_test_upload_preset2");
            Assert.AreEqual(presets.Presets[1].Name, "api_test_upload_preset");

            var delResult = m_cloudinary.DeleteUploadPreset("api_test_upload_preset");
            Assert.AreEqual("deleted", delResult.Message);
            delResult = m_cloudinary.DeleteUploadPreset("api_test_upload_preset2");
            Assert.AreEqual("deleted", delResult.Message);
        }