Пример #1
0
        public static void Copy(string bucket, string key, CopySourceStruct copySource)
        {
            COSXMLCopyTask copyTask = new COSXMLCopyTask(bucket, null, key, copySource)
            {
                successCallback = delegate(CosResult cosResult)
                {
                    COSXML.Transfer.COSXMLCopyTask.CopyTaskResult result = cosResult as COSXML.Transfer.COSXMLCopyTask.CopyTaskResult;
                    QLog.D("XIAO", result.GetResultInfo());
                    Console.WriteLine(result.GetResultInfo());
                    Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId));
                },
                failCallback = 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));
                }
            };

            transferManager.Copy(copyTask);
        }
Пример #2
0
        /// 高级接口拷贝对象
        public async void TransferCopyObject()
        {
            TransferConfig transferConfig = new TransferConfig();

            // 初始化 TransferManager
            TransferManager transferManager = new TransferManager(cosXml, transferConfig);

            //.cssg-snippet-body-start:[transfer-copy-object]
            string sourceAppid  = "1250000000";              //账号 appid
            string sourceBucket = "sourcebucket-1250000000"; //"源对象所在的存储桶
            string sourceRegion = "COS_REGION";              //源对象的存储桶所在的地域
            string sourceKey    = "sourceObject";            //源对象键
            //构造源对象属性
            CopySourceStruct copySource = new CopySourceStruct(sourceAppid, sourceBucket,
                                                               sourceRegion, sourceKey);

            string bucket = "examplebucket-1250000000"; //目标存储桶,格式:BucketName-APPID
            string key    = "exampleobject";            //目标对象的对象键

            COSXMLCopyTask copytask = new COSXMLCopyTask(bucket, key, copySource);

            try {
                COSXML.Transfer.COSXMLCopyTask.CopyTaskResult result = await
                                                                       transferManager.CopyAsync(copytask);

                Console.WriteLine(result.GetResultInfo());
                string eTag = result.eTag;
            } catch (Exception e) {
                Console.WriteLine("CosException: " + e);
            }

            //.cssg-snippet-body-end
        }
        /// 高级接口拷贝对象
        public void TransferCopyObject()
        {
            TransferConfig transferConfig = new TransferConfig();

            // 初始化 TransferManager
            TransferManager transferManager = new TransferManager(cosXml, transferConfig);

            //.cssg-snippet-body-start:[transfer-copy-object]
            string sourceAppid  = "1250000000";              //账号 appid
            string sourceBucket = "sourcebucket-1250000000"; //"源对象所在的存储桶
            string sourceRegion = "COS_REGION";              //源对象的存储桶所在的地域
            string sourceKey    = "sourceObject";            //源对象键
            //构造源对象属性
            CopySourceStruct copySource = new CopySourceStruct(sourceAppid, sourceBucket,
                                                               sourceRegion, sourceKey);

            string bucket = "examplebucket-1250000000"; //目标存储桶,格式:BucketName-APPID
            string key    = "exampleobject";            //目标对象的对象键

            COSXMLCopyTask copytask = new COSXMLCopyTask(bucket, key, copySource);

            copytask.successCallback = delegate(CosResult cosResult)
            {
                COSXML.Transfer.COSXMLCopyTask.CopyTaskResult result = cosResult
                                                                       as COSXML.Transfer.COSXMLCopyTask.CopyTaskResult;
                Console.WriteLine(result.GetResultInfo());
                string eTag = result.eTag;
            };
            copytask.failCallback = delegate(CosClientException clientEx, CosServerException serverEx)
            {
                if (clientEx != null)
                {
                    Console.WriteLine("CosClientException: " + clientEx);
                }
                if (serverEx != null)
                {
                    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                }
            };
            transferManager.Copy(copytask);

            //.cssg-snippet-body-end
        }
Пример #4
0
        public void testCopyTask()
        {
            CopySourceStruct copySource = new CopySourceStruct(QCloudServer.Instance().appid,
                                                               bucket, QCloudServer.Instance().region, copykey);

            COSXMLCopyTask copyTask = new COSXMLCopyTask(bucket, multiKey, copySource);

            var autoEvent = new AutoResetEvent(false);

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

            copyTask.successCallback = delegate(CosResult cosResult)
            {
                COSXML.Transfer.COSXMLCopyTask.CopyTaskResult result = cosResult as COSXML.Transfer.COSXMLCopyTask.CopyTaskResult;
                Console.WriteLine(result.GetResultInfo());
                autoEvent.Set();
                Assert.True(cosResult.httpCode == 200);
            };

            copyTask.failCallback = delegate(CosClientException clientEx, CosServerException serverEx)
            {
                if (clientEx != null)
                {
                    Console.WriteLine("CosClientException: " + clientEx);
                }
                if (serverEx != null)
                {
                    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                }
                autoEvent.Set();
                Assert.True(false);
            };

            transferManager.Copy(copyTask);
            autoEvent.WaitOne();
        }