コード例 #1
0
ファイル: KS3Sample.cs プロジェクト: elvismile/ks3sdk-csharp
        public static bool setBucketCors()
        {
            try
            {
                Console.WriteLine("--- setBucketCors: ---");
                Console.WriteLine("Bucket Name: " + bucketName);
                PutBucketCorsRequest putBucketCorsRequest = new PutBucketCorsRequest();
                putBucketCorsRequest.BucketName = bucketName;
                BucketCorsConfigurationResult bucketCorsConfiguration = new BucketCorsConfigurationResult();
                IList <CorsRule> corsRule = new List <CorsRule>();
                CorsRule         rule     = new CorsRule();
                rule.AllowedMethods.Add(HttpMethod.PUT);
                rule.AllowedHeaders.Add("*");
                rule.AllowedOrigins.Add("http://www.example.com");
                rule.AllowedOrigins.Add("http://www.example.a.com");
                rule.ExposedHeaders.Add("*");
                rule.MaxAgeSeconds = 200;
                corsRule.Add(rule);
                bucketCorsConfiguration.Rules = corsRule;
                putBucketCorsRequest.BucketCorsConfiguration = bucketCorsConfiguration;

                ks3Client.setBucketCors(putBucketCorsRequest);

                Console.WriteLine("Success.");
                Console.WriteLine("----------------------\n");
            }
            catch (System.Exception e)
            {
                Console.WriteLine("setBucketCors Fail! " + e.ToString());
                return(false);
            }
            return(true);
        }
コード例 #2
0
ファイル: UnitTestKs3.cs プロジェクト: jflzbest/C-
        public void TestSetBucketCors()
        {
            if (init())
            {
                PutBucketCorsRequest putBucketCorsRequest = new PutBucketCorsRequest();
                putBucketCorsRequest.BucketName = bucketName;
                BucketCorsConfigurationResult bucketCorsConfiguration = new BucketCorsConfigurationResult();
                IList <CorsRule> corsRule = new List <CorsRule>();
                CorsRule         rule     = new CorsRule();
                rule.AllowedMethods.Add(HttpMethod.PUT);
                rule.AllowedHeaders.Add("*");
                rule.AllowedOrigins.Add("http://www.example.com");
                rule.AllowedOrigins.Add("http://www.example.a.com");
                rule.ExposedHeaders.Add("*");
                rule.MaxAgeSeconds = 200;
                corsRule.Add(rule);
                bucketCorsConfiguration.Rules = corsRule;
                putBucketCorsRequest.BucketCorsConfiguration = bucketCorsConfiguration;

                ks3Client.setBucketCors(putBucketCorsRequest);
            }
        }