Пример #1
0
        public static void AsynOptionObject(COSXML.CosXml cosXml, string bucket, string key, string origin, string accessMthod)
        {
            QLog.D("XIAO", String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId));
            OptionObjectRequest request = new OptionObjectRequest(bucket, key, origin, accessMthod);

            //设置签名有效时长
            request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

            cosXml.OptionObject(request,
                                delegate(CosResult cosResult)
            {
                OptionObjectResult result = cosResult as OptionObjectResult;
                Console.WriteLine(result.GetResultInfo());
                Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId));
            },
                                delegate(CosClientException clientEx, CosServerException serverEx)
            {
                if (clientEx != null)
                {
                    QLog.D("XIAO", clientEx.Message);
                    Console.WriteLine("CosClientException: " + clientEx.StackTrace);
                }
                if (serverEx != null)
                {
                    QLog.D("XIAO", serverEx.Message);
                    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                }
                Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId));
            });
        }
Пример #2
0
        /// 实现 Object 跨域访问配置的预请求
        public void OptionObject()
        {
            //.cssg-snippet-body-start:[option-object]
            try
            {
                string bucket               = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID
                string key                  = "exampleobject";            //对象键
                string origin               = "http://cloud.tencent.com";
                string accessMthod          = "PUT";
                OptionObjectRequest request = new OptionObjectRequest(bucket, key, origin, accessMthod);
                //执行请求
                OptionObjectResult result = cosXml.OptionObject(request);
                //请求成功
                Console.WriteLine(result.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                //请求失败
                Console.WriteLine("CosClientException: " + clientEx);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                //请求失败
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
            }

            //.cssg-snippet-body-end
        }
Пример #3
0
        public void AsynOptionObject(COSXML.CosXml cosXml, string bucket, string key)
        {
            string origin               = "http://cloud.tencent.com";
            string accessMthod          = "PUT";
            OptionObjectRequest request = new OptionObjectRequest(bucket, key, origin, accessMthod);

            //设置签名有效时长
            request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

            cosXml.OptionObject(request,
                                delegate(CosResult cosResult)
            {
                OptionObjectResult result = cosResult as OptionObjectResult;
                Console.WriteLine(result.GetResultInfo());
                manualResetEvent.Set();
            },
                                delegate(CosClientException clientEx, CosServerException serverEx)
            {
                if (clientEx != null)
                {
                    Console.WriteLine("CosClientException: " + clientEx.Message);
                }
                if (serverEx != null)
                {
                    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                }

                manualResetEvent.Set();
            });
        }
Пример #4
0
        public void OptionObject(COSXML.CosXml cosXml, string bucket, string key)
        {
            try
            {
                string origin               = "http://cloud.tencent.com";
                string accessMthod          = "PUT";
                OptionObjectRequest request = new OptionObjectRequest(bucket, key, origin, accessMthod);
                //设置签名有效时长
                request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                //执行请求
                OptionObjectResult result = cosXml.OptionObject(request);

                Console.WriteLine(result.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.StackTrace);
                Assert.True(false);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.True(false);
            }
        }
Пример #5
0
        public void optionObject()
        {
            //.cssg-snippet-body-start:[option-object]
            CosXmlConfig config = new CosXmlConfig.Builder()
                                  .SetConnectionTimeoutMs(60000) //设置连接超时时间,单位毫秒,默认45000ms
                                  .SetReadWriteTimeoutMs(40000)  //设置读写超时时间,单位毫秒,默认45000ms
                                  .IsHttps(true)                 //设置默认 HTTPS 请求
                                  .SetAppid("1253653367")        //设置腾讯云账户的账户标识 APPID
                                  .SetRegion("ap-guangzhou")     //设置一个默认的存储桶地域
                                  .Build();

            string secretId       = Environment.GetEnvironmentVariable("COS_KEY");    //云 API 密钥 SecretId
            string secretKey      = Environment.GetEnvironmentVariable("COS_SECRET"); //云 API 密钥 SecretKey
            long   durationSecond = 600;                                              //每次请求签名有效时长,单位为秒
            QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId,
                                                                                                    secretKey, durationSecond);

            CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider);

            try
            {
                string bucket               = "bucket-cssg-test-dotnet-1253653367"; //存储桶,格式:BucketName-APPID
                string key                  = "object4dotnet";                      //对象在存储桶中的位置,即称对象键
                string origin               = "http://cloud.tencent.com";
                string accessMthod          = "PUT";
                OptionObjectRequest request = new OptionObjectRequest(bucket, key, origin, accessMthod);
                //设置签名有效时长
                request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
                //执行请求
                OptionObjectResult result = cosXml.OptionObject(request);
                //请求成功
                Console.WriteLine(result.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                //请求失败
                Console.WriteLine("CosClientException: " + clientEx);
                Assert.Null(clientEx);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                //请求失败
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.Null(serverEx);
            }
            //.cssg-snippet-body-end
        }
Пример #6
0
        public static void OptionObject(COSXML.CosXml cosXml, string bucket, string key, string origin, string accessMthod)
        {
            try
            {
                OptionObjectRequest request = new OptionObjectRequest(bucket, key, origin, accessMthod);
                //设置签名有效时长
                request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                //执行请求
                OptionObjectResult result = cosXml.OptionObject(request);

                Console.WriteLine(result.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                QLog.D("XIAO", clientEx.Message);
                Console.WriteLine("CosClientException: " + clientEx.StackTrace);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                QLog.D("XIAO", serverEx.Message);
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
            }
        }
Пример #7
0
        public void OptionObject()
        {
            try
            {
                string origin               = "http://cloud.tencent.com";
                string accessMthod          = "PUT";
                OptionObjectRequest request = new OptionObjectRequest(bucket, commonKey, origin, accessMthod);

                //执行请求
                OptionObjectResult result = cosXml.OptionObject(request);

                Console.WriteLine(result.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.StackTrace);
                Assert.True(false);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.True(false);
            }
        }