Esempio n. 1
0
        public void PutObjectWithAES256(COSXML.CosXml cosXml, string bucket, string key, string srcPath)
        {
            try
            {
                PutObjectRequest request = new PutObjectRequest(bucket, key, srcPath);
                //设置签名有效时长
                request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

                //设置进度回调
                request.SetCosProgressCallback(delegate(long completed, long total)
                {
                    //Console.WriteLine(String.Format("{0} progress = {1} / {2} : {3:##.##}%", DateTime.Now.ToString(), completed, total, completed * 100.0 / total));
                });

                request.SetCosServerSideEncryption();

                //执行请求
                PutObjectResult result = cosXml.PutObject(request);

                Console.WriteLine(result.GetResultInfo());
            }
            catch (CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.True(false);
            }
            catch (CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.True(false);
            }
        }
Esempio n. 2
0
        public void PutObjectWithAES256()
        {
            try
            {
                string           key     = "objectWithAES256";
                PutObjectRequest request = new PutObjectRequest(bucket, key, smallFileSrcPath);

                request.SetCosServerSideEncryption();

                //执行请求
                PutObjectResult result = cosXml.PutObject(request);

                Console.WriteLine(result.GetResultInfo());
            }
            catch (CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.StackTrace);
                Assert.True(false);
            }
            catch (CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.True(false);
            }
        }
Esempio n. 3
0
        /// 使用 COS 托管加密密钥的服务端加密(SSE-COS)保护数据
        public void PutObjectSse()
        {
            string bucket  = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID
            string key     = "exampleobject";            //对象键
            string srcPath = @"temp-source-file";        //本地文件绝对路径
            //.cssg-snippet-body-start:[put-object-sse]
            PutObjectRequest request = new PutObjectRequest(bucket, key, srcPath);

            request.SetCosServerSideEncryption();
            //.cssg-snippet-body-end
        }