Exemple #1
0
 public async Task <MultiResult> MultiAsync(MultiParams parameters)
 {
     using (var response = await Api.CallAsync(HttpMethod.Post, Api.ApiUrlImgUpV.Action("multi").BuildUrl(), parameters.ToParamsDictionary(), null, null))
     {
         return(await MultiResult.Parse(response));
     }
 }
        public void TestMultiTransformation()
        {
            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File     = new FileDescription(m_testImagePath),
                Tags     = "test--5",
                PublicId = "test--5-1"
            };

            m_cloudinary.Upload(uploadParams);

            uploadParams.PublicId       = "test--5-2";
            uploadParams.Transformation = new Transformation().Width(100).Height(300);

            m_cloudinary.Upload(uploadParams);

            MultiParams multi  = new MultiParams("test--5");
            MultiResult result = m_cloudinary.Multi(multi);

            Assert.True(result.Uri.AbsoluteUri.EndsWith(".gif"));

            multi.Transformation = new Transformation().Width(100);
            result = m_cloudinary.Multi(multi);
            Assert.True(result.Uri.AbsoluteUri.Contains("w_100"));

            multi.Transformation = new Transformation().Width(111);
            multi.Format         = "pdf";
            result = m_cloudinary.Multi(multi);
            Assert.True(result.Uri.AbsoluteUri.Contains("w_111"));
            Assert.True(result.Uri.AbsoluteUri.EndsWith(".pdf"));
        }
Exemple #3
0
        public void TestDownloadMulti()
        {
            const string multiTestTag = "multi_test_tag";
            const string url1         = "https://res.cloudinary.com/demo/image/upload/sample";
            const string url2         = "https://res.cloudinary.com/demo/image/upload/car";

            var paramsFromTag = new MultiParams(multiTestTag);
            var urlFromTag    = m_cloudinary.DownloadMulti(paramsFromTag);
            var paramsFromUrl = new MultiParams(new List <string> {
                url1, url2
            });
            var urlFromUrls = m_cloudinary.DownloadMulti(paramsFromUrl);

            var expectedUrl = "https://api.cloudinary.com/v1_1/" + m_cloudinary.Api.Account.Cloud + "/image/multi";
            var uriFromTag  = new Uri(urlFromTag);
            var uriFromUrls = new Uri(urlFromUrls);

            Assert.True(uriFromTag.ToString().StartsWith(expectedUrl));
            Assert.True(uriFromUrls.ToString().StartsWith(expectedUrl));

            var uriParamsFromTag = HttpUtility.ParseQueryString(uriFromTag.Query);

            Assert.AreEqual("download", uriParamsFromTag["mode"]);
            Assert.AreEqual(multiTestTag, uriParamsFromTag["tag"]);
            Assert.NotNull(uriParamsFromTag["timestamp"]);
            Assert.NotNull(uriParamsFromTag["signature"]);

            var uriParamsFromUrls = HttpUtility.ParseQueryString(uriFromUrls.Query);

            Assert.AreEqual("download", uriParamsFromUrls["mode"]);
            Assert.True(uriParamsFromUrls["urls[]"].Contains(url1));
            Assert.True(uriParamsFromUrls["urls[]"].Contains(url2));
            Assert.NotNull(uriParamsFromUrls["timestamp"]);
            Assert.NotNull(uriParamsFromUrls["signature"]);
        }
        /// <summary>
        /// Allows multi transformation
        /// </summary>
        /// <param name="parameters">Parameters of operation</param>
        /// <returns>Result of operation</returns>
        public MultiResult Multi(MultiParams parameters)
        {
            UrlBuilder urlBuilder = new UrlBuilder(
                m_api.ApiUrlImgUpV.
                Action("multi").
                BuildUrl());

            using (HttpWebResponse response = m_api.Call(
                       HttpMethod.POST, urlBuilder.ToString(), parameters.ToParamsDictionary(), null))
            {
                MultiResult result = MultiResult.Parse(response);
                return(result);
            }
        }
Exemple #5
0
        public async Task TestMultiTransformationAsync()
        {
            var tag           = GetMethodTag();
            var uploadResult1 = await UploadTestImageResourceAsync((uploadParams) =>
            {
                uploadParams.Tags = $"{tag},{m_apiTag}";
            },
                                                                   StorageType.multi);

            var uploadResult2 = await UploadTestImageResourceAsync((uploadParams) =>
            {
                uploadParams.Tags           = $"{tag},{m_apiTag}";
                uploadParams.Transformation = m_simpleTransformation;
            },
                                                                   StorageType.multi);

            var urls = new List <string> {
                uploadResult1.Url.ToString(), uploadResult2.Url.ToString()
            };
            var multiParams = new MultiParams(urls);
            var result      = await m_cloudinary.MultiAsync(multiParams);

            AddCreatedPublicId(StorageType.multi, result.PublicId);
            AssertMultiResult(result, null, FILE_FORMAT_GIF);

            multiParams = new MultiParams(tag);
            result      = await m_cloudinary.MultiAsync(multiParams);

            AddCreatedPublicId(StorageType.multi, result.PublicId);
            AssertMultiResult(result, null, FILE_FORMAT_GIF);

            multiParams.Transformation = m_resizeTransformation;
            result = await m_cloudinary.MultiAsync(multiParams);

            AddCreatedPublicId(StorageType.multi, result.PublicId);
            AssertMultiResult(result, TRANSFORM_W_512, null);

            multiParams.Transformation = m_simpleTransformationAngle;
            multiParams.Format         = FILE_FORMAT_PDF;
            result = await m_cloudinary.MultiAsync(multiParams);

            AddCreatedPublicId(StorageType.multi, result.PublicId);
            AssertMultiResult(result, TRANSFORM_A_45, FILE_FORMAT_PDF);
        }
Exemple #6
0
        public void TestMultiTransformation()
        {
            var tag = GetMethodTag();

            UploadTestImageResource((uploadParams) =>
            {
                uploadParams.Tags = $"{tag},{m_apiTag}";
            },
                                    StorageType.multi);

            UploadTestImageResource((uploadParams) =>
            {
                uploadParams.Tags           = $"{tag},{m_apiTag}";
                uploadParams.Transformation = m_simpleTransformation;
            },
                                    StorageType.multi);

            var multiParams = new MultiParams(tag);

            var result = m_cloudinary.Multi(multiParams);

            AddCreatedPublicId(StorageType.multi, result.PublicId);

            AssertMultiResult(result, null, FILE_FORMAT_GIF);

            multiParams.Transformation = m_resizeTransformation;

            result = m_cloudinary.Multi(multiParams);

            AddCreatedPublicId(StorageType.multi, result.PublicId);

            AssertMultiResult(result, TRANSFORM_W_512, null);

            multiParams.Transformation = m_simpleTransformationAngle;
            multiParams.Format         = FILE_FORMAT_PDF;

            result = m_cloudinary.Multi(multiParams);

            AddCreatedPublicId(StorageType.multi, result.PublicId);

            AssertMultiResult(result, TRANSFORM_A_45, FILE_FORMAT_PDF);
        }
Exemple #7
0
        public void TestMultiTransformation()
        {
            var publicId1 = GetUniquePublicId(StorageType.multi);
            var publicId2 = GetUniquePublicId(StorageType.multi);
            var tag       = GetMethodTag();

            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File     = new FileDescription(m_testImagePath),
                Tags     = $"{tag},{m_apiTag}",
                PublicId = publicId1
            };

            m_cloudinary.Upload(uploadParams);

            uploadParams.PublicId       = publicId2;
            uploadParams.Transformation = m_simpleTransformation;
            m_cloudinary.Upload(uploadParams);

            MultiParams multi  = new MultiParams(tag);
            MultiResult result = m_cloudinary.Multi(multi);

            AddCreatedPublicId(StorageType.multi, result.PublicId);
            Assert.True(result.Uri.AbsoluteUri.EndsWith($".{FILE_FORMAT_GIF}"));

            multi.Transformation = m_resizeTransformation;
            result = m_cloudinary.Multi(multi);
            AddCreatedPublicId(StorageType.multi, result.PublicId);
            Assert.IsTrue(result.Uri.AbsoluteUri.Contains(TRANSFORM_W_512));

            multi.Transformation = m_simpleTransformationAngle;
            multi.Format         = FILE_FORMAT_PDF;
            result = m_cloudinary.Multi(multi);
            AddCreatedPublicId(StorageType.multi, result.PublicId);

            Assert.True(result.Uri.AbsoluteUri.Contains(TRANSFORM_A_45));
            Assert.True(result.Uri.AbsoluteUri.EndsWith($".{FILE_FORMAT_PDF}"));
        }
 /// <summary>
 /// Allows multi transformation
 /// </summary>
 /// <param name="parameters">Parameters of operation</param>
 /// <returns>Result of operation</returns>
 public Task <MultiResult> MultiAsync(MultiParams parameters)
 {
     return(CallAsync(Multi, parameters));
 }
 public static MultiResult Multi(this Cloudinary cloudinary, MultiParams parameters)
 {
     return(cloudinary.MultiAsync(parameters).ExecSync());
 }