示例#1
0
        public void CopyObject()
        {
            try
            {
                CopySourceStruct copySource = new CopySourceStruct(QCloudServer.Instance().appid,
                                                                   bucket, QCloudServer.Instance().region, copykey);

                CopyObjectRequest request = new CopyObjectRequest(bucket, multiKey);

                //设置拷贝源
                request.SetCopySource(copySource);

                //设置是否拷贝还是更新
                request.SetCopyMetaDataDirective(COSXML.Common.CosMetaDataDirective.COPY);

                //执行请求
                CopyObjectResult result = cosXml.CopyObject(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);
            }
        }
示例#2
0
        public static void CopyObject(COSXML.CosXml cosXml, string bucket, string key, COSXML.Model.Tag.CopySourceStruct copySource)
        {
            try
            {
                CopyObjectRequest request = new CopyObjectRequest(bucket, key);
                //设置签名有效时长
                request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                //设置拷贝源
                request.SetCopySource(copySource);

                //设置是否拷贝还是更新
                request.SetCopyMetaDataDirective(COSXML.Common.CosMetaDataDirective.COPY);

                //执行请求
                CopyObjectResult result = cosXml.CopyObject(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 AsynCopyObject(COSXML.CosXml cosXml, string bucket, string key, COSXML.Model.Tag.CopySourceStruct copySource)
        {
            CopyObjectRequest request = new CopyObjectRequest(bucket, key);

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

            //设置拷贝源
            request.SetCopySource(copySource);

            //设置是否拷贝还是更新
            request.SetCopyMetaDataDirective(COSXML.Common.CosMetaDataDirective.COPY);

            cosXml.CopyObject(request,
                              delegate(CosResult cosResult)
            {
                CopyObjectResult result = cosResult as CopyObjectResult;
                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 static void AsynCopyObject(COSXML.CosXml cosXml, string bucket, string key, COSXML.Model.Tag.CopySourceStruct copySource)
        {
            QLog.D("XIAO", String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId));
            CopyObjectRequest request = new CopyObjectRequest(bucket, key);

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

            //设置拷贝源
            request.SetCopySource(copySource);

            //设置是否拷贝还是更新
            request.SetCopyMetaDataDirective(COSXML.Common.CosMetaDataDirective.COPY);

            cosXml.CopyObject(request,
                              delegate(CosResult cosResult)
            {
                CopyObjectResult result = cosResult as CopyObjectResult;
                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));
            });
        }