コード例 #1
0
        public static void AsynPostObject(COSXML.CosXml cosXml, string bucket, string key, string srcPath, PostObjectRequest.Policy policy)
        {
            PostObjectRequest request = new PostObjectRequest(bucket, key, srcPath);

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

            request.SetCosProgressCallback(delegate(long completed, long total)
            {
                Console.WriteLine(String.Format("progress = {0} / {1} : {2:##.##}%", completed, total, completed * 100.0 / total));
            });

            //设置policy
            request.SetPolicy(policy);

            //执行请求
            cosXml.PostObject(request, delegate(CosResult result)
            {
                PostObjectResult getObjectResult = result as PostObjectResult;
                Console.WriteLine(getObjectResult.GetResultInfo());
            }, 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());
                }
            });
        }
コード例 #2
0
        public static void PostObject(COSXML.CosXml cosXml, string bucket, string key, string srcPath, PostObjectRequest.Policy policy)
        {
            try
            {
                PostObjectRequest request = new PostObjectRequest(bucket, key, srcPath);
                //设置签名有效时长
                //request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
                List <string> headers = new List <string>();
                headers.Add("Host");
                request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600, headers, null);

                request.SetCosProgressCallback(delegate(long completed, long total)
                {
                    Console.WriteLine(String.Format("progress = {0} / {1} : {2:##.##}%", completed, total, completed * 100.0 / total));
                });

                //设置policy
                request.SetPolicy(policy);

                //执行请求
                PostObjectResult result = cosXml.PostObject(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());
            }
        }
コード例 #3
0
        public void PostObject()
        {
            try
            {
                PostObjectRequest request = new PostObjectRequest(bucket, commonKey, smallFileSrcPath);
                List <string>     headers = new List <string>();
                headers.Add("Host");

                request.SetCosProgressCallback(delegate(long completed, long total)
                {
                    Console.WriteLine(String.Format("progress = {0} / {1} : {2:##.##}%", completed, total, completed * 100.0 / total));
                });

                //设置policy
                request.SetPolicy(null);

                //执行请求
                PostObjectResult result = cosXml.PostObject(request);

                Console.WriteLine(result.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.True(false);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.True(false);
            }
        }
コード例 #4
0
        public void testPostObjectTrafficLimit()
        {
            try
            {
                long now = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
                PostObjectRequest request = new PostObjectRequest(bucket,
                                                                  commonKey, smallFileSrcPath);

                request.LimitTraffic(8 * 1000 * 1024);
                //执行请求
                PostObjectResult result   = cosXml.PostObject(request);
                long             costTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds() - now;

                Console.WriteLine("costTime = " + costTime + "ms");
                Console.WriteLine(result.GetResultInfo());

                Assert.True(result.httpCode == 204);
                // Assert.True(costTime > 8000 && costTime < 14000);
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.True(false);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.True(false);
            }
        }
コード例 #5
0
        /// POST 方式上传对象
        public void PostObject()
        {
            //.cssg-snippet-body-start:[post-object]
            try
            {
                string            bucket  = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID
                string            key     = "exampleobject";            //对象键
                string            srcPath = @"temp-source-file";        //本地文件绝对路径
                PostObjectRequest request = new PostObjectRequest(bucket, key, srcPath);
                //设置进度回调
                request.SetCosProgressCallback(delegate(long completed, long total)
                {
                    Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));
                });
                //执行请求
                PostObjectResult result = cosXml.PostObject(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
        }