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); } }
public static void PutObject(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)); }); //执行请求 PutObjectResult result = cosXml.PutObject(request); Console.WriteLine(String.Format("{0} {1}", DateTime.Now.ToString(), result.GetResultInfo())); } catch (CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } catch (CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
public void testPutObjectUploadTrafficLimit() { try { long now = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds(); PutObjectRequest request = new PutObjectRequest(bucket, commonKey, smallFileSrcPath); request.LimitTraffic(8 * 1000 * 1024); //执行请求 PutObjectResult result = cosXml.PutObject(request); long costTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds() - now; Console.WriteLine("costTime = " + costTime + "ms"); Console.WriteLine(result.GetResultInfo()); Assert.True(result.httpCode == 200); // 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); } }
public void PutObject() { init(); string bucket = "000000-1253653367"; string objectKey = "文件夹/exampleobject"; try { PutObjectRequest request = new PutObjectRequest(bucket, objectKey, smallFileSrcPath); //执行请求 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); } }
public void PutObjectWithKMS(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.IsHttps = true; //设置进度回调 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.SetCosServerSideEncryptionWithKMS(null, null); //执行请求 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(true); } }
public int Upload(string src, string key) { try { string bucket = _bucket; // "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID // string key = "exampleobject"; //对象在存储桶中的位置,即称对象键. string srcPath = src; // @"F:\exampleobject";//本地文件绝对路径 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("progress = {0:##.##}%", completed * 100.0 / total)); }); //执行请求 PutObjectResult result = cosXml.PutObject(request); //请求成功 string r = result.GetResultInfo(); Console.WriteLine(r); return(0); } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 Console.WriteLine("CosClientException: " + clientEx.Message); } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } return(1); }
public void PutObjectWithCustomerKey() { try { string key = "objectWithSSEC"; PutObjectRequest request = new PutObjectRequest(bucket, key, smallFileSrcPath); string customerKey = "25rN73uQtl1bUGnvHe0URgFWBNu4vBba";//32字符 request.SetCosServerSideEncryptionWithCustomerKey(customerKey); //执行请求 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); } }
public async Task <ResponseModel> UpFile(string key, string srcPath) { try { string bucket = _buketName + "-" + _appid; //存储桶名称 格式:BucketName-APPID 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("progress = {0:##.##}%", completed * 100.0 / total)); }); //执行请求 PutObjectResult result = await Task.FromResult(_cosXml.PutObject(request)); return(new ResponseModel { Code = 200, Message = result.GetResultInfo() }); } catch (CosClientException clientEx) { return(new ResponseModel { Code = 0, Message = "CosClientException: " + clientEx.Message }); } catch (CosServerException serverEx) { return(new ResponseModel { Code = 0, Message = "CosServerException: " + serverEx.GetInfo() }); } }
public void PutObjectWithDeSample() { string key = "original_photo.jpg"; string srcPath = localTempPhotoFilePath; PutObjectRequest request = new PutObjectRequest(bucket, key, srcPath); JObject o = new JObject(); // 返回原图 o["is_pic_info"] = 1; JArray rules = new JArray(); JObject rule = new JObject(); rule["bucket"] = bucket; rule["fileid"] = "desample_photo.jpg"; //处理参数,规则参见:https://cloud.tencent.com/document/product/460/19017 rule["rule"] = "imageMogr2/thumbnail/400x"; rules.Add(rule); o["rules"] = rules; string ruleString = o.ToString(Formatting.None); request.SetRequestHeader("Pic-Operations", ruleString); //执行请求 PutObjectResult result = QCloudServer.Instance().cosXml.PutObject(request); var uploadResult = result.uploadResult; // Console.WriteLine(result.GetResultInfo()); Assert.IsNotEmpty((result.GetResultInfo())); Assert.True(result.IsSuccessful()); Assert.NotNull(uploadResult); Assert.NotNull(uploadResult.originalInfo); Assert.NotNull(uploadResult.originalInfo.ETag); Assert.NotNull(uploadResult.originalInfo.Key); Assert.NotNull(uploadResult.originalInfo.Location); Assert.NotNull(uploadResult.originalInfo.imageInfo.Ave); Assert.NotNull(uploadResult.originalInfo.imageInfo.Format); Assert.NotNull(uploadResult.originalInfo.imageInfo.Orientation); Assert.NotZero(uploadResult.originalInfo.imageInfo.Width); Assert.NotZero(uploadResult.originalInfo.imageInfo.Height); Assert.NotZero(uploadResult.originalInfo.imageInfo.Quality); Assert.NotNull(uploadResult.processResults); Assert.NotZero(uploadResult.processResults.results.Count); Assert.True(uploadResult.processResults.results[0].Width <= 400); Assert.True(uploadResult.processResults.results[0].Height <= 400); Assert.NotNull(uploadResult.processResults.results[0].ETag); Assert.NotNull(uploadResult.processResults.results[0].Format); Assert.NotNull(uploadResult.processResults.results[0].Key); Assert.NotNull(uploadResult.processResults.results[0].Location); Assert.NotZero(uploadResult.processResults.results[0].Quality); Assert.NotZero(uploadResult.processResults.results[0].Size); Assert.Zero(uploadResult.processResults.results[0].WatermarkStatus); }
internal static string PutObject(CosXmlServer cosXml) { string cosKey = "cosKey"; byte[] tmpData = new byte[1024]; PutObjectRequest request = new PutObjectRequest(bucket, cosKey, tmpData); PutObjectResult result = cosXml.PutObject(request); Console.WriteLine(result.GetResultInfo()); return(cosKey); }
public void AsynPutObject(COSXML.CosXml cosXml, string bucket, string key, string srcPath) { 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("progress = {0} / {1} : {2:##.##}%", completed, total, completed * 100.0 / total)); }); //添加acl request.SetCosACL(CosACL.PRIVATE); COSXML.Model.Tag.GrantAccount readAccount = new COSXML.Model.Tag.GrantAccount(); readAccount.AddGrantAccount("1131975903", "1131975903"); request.SetXCosGrantRead(readAccount); COSXML.Model.Tag.GrantAccount writeAccount = new COSXML.Model.Tag.GrantAccount(); writeAccount.AddGrantAccount("1131975903", "1131975903"); request.SetXCosGrantWrite(writeAccount); COSXML.Model.Tag.GrantAccount fullAccount = new COSXML.Model.Tag.GrantAccount(); fullAccount.AddGrantAccount("2832742109", "2832742109"); request.SetXCosReadWrite(fullAccount); cosXml.PutObject(request, delegate(CosResult cosResult) { PutObjectResult result = cosResult as PutObjectResult; 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(); }); }
/// 获取预签名上传链接 public void GetPresignUploadUrl() { //.cssg-snippet-body-start:[get-presign-upload-url] try { PreSignatureStruct preSignatureStruct = new PreSignatureStruct(); preSignatureStruct.appid = "1250000000"; //腾讯云账号 APPID preSignatureStruct.region = "COS_REGION"; //存储桶地域 preSignatureStruct.bucket = "examplebucket-1250000000"; //存储桶 preSignatureStruct.key = "exampleobject"; //对象键 preSignatureStruct.httpMethod = "PUT"; //HTTP 请求方法 preSignatureStruct.isHttps = true; //生成 HTTPS 请求 URL preSignatureStruct.signDurationSecond = 600; //请求签名时间为 600s preSignatureStruct.headers = null; //签名中需要校验的 header preSignatureStruct.queryParameters = null; //签名中需要校验的 URL 中请求参数 //上传预签名 URL (使用永久密钥方式计算的签名 URL) string requestSignURL = cosXml.GenerateSignURL(preSignatureStruct); string srcPath = @"temp-source-file";//本地文件绝地路径 PutObjectRequest request = new PutObjectRequest(null, null, srcPath); //设置上传请求预签名 URL request.RequestURLWithSign = requestSignURL; //设置进度回调 request.SetCosProgressCallback(delegate(long completed, long total) { Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total)); }); //执行请求 PutObjectResult result = cosXml.PutObject(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 }
public void AsynPutObject() { AutoResetEvent resetEvent = new AutoResetEvent(false); PutObjectRequest request = new PutObjectRequest(bucket, commonKey, smallFileSrcPath); //添加acl request.SetCosACL(CosACL.PRIVATE); COSXML.Model.Tag.GrantAccount readAccount = new COSXML.Model.Tag.GrantAccount(); readAccount.AddGrantAccount("1131975903", "1131975903"); request.SetXCosGrantRead(readAccount); COSXML.Model.Tag.GrantAccount writeAccount = new COSXML.Model.Tag.GrantAccount(); writeAccount.AddGrantAccount("1131975903", "1131975903"); request.SetXCosGrantWrite(writeAccount); COSXML.Model.Tag.GrantAccount fullAccount = new COSXML.Model.Tag.GrantAccount(); fullAccount.AddGrantAccount("2832742109", "2832742109"); request.SetXCosReadWrite(fullAccount); cosXml.PutObject(request, delegate(CosResult cosResult) { PutObjectResult result = cosResult as PutObjectResult; Console.WriteLine(result.GetResultInfo()); resetEvent.Set(); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { Console.WriteLine("CosClientException: " + clientEx.Message); } if (serverEx != null) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } resetEvent.Set(); }); resetEvent.WaitOne(); }
public void PutObject() { try { PutObjectRequest request = new PutObjectRequest(bucket, commonKey, smallFileSrcPath); //执行请求 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); } }
public void testCreateDirectory() { try { PutObjectRequest request = new PutObjectRequest(bucket, "dir/", new byte[0]); //执行请求 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); } }
public static void AsynPutObject(COSXML.CosXml cosXml, string bucket, string key, string srcPath) { QLog.D("XIAO", String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); 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("progress = {0} / {1} : {2:##.##}%", completed, total, completed * 100.0 / total)); }); cosXml.PutObject(request, delegate(CosResult cosResult) { PutObjectResult result = cosResult as PutObjectResult; 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)); }); }
public void QRCodeRecognition() { string key = qrPhotoKey; // 下载云上有内容的 QR Code string srcPath = localQRCodeTempPhotoFilePath; GetObjectRequest getRequest = new GetObjectRequest(bucket, key, ".", localQRCodeTempPhotoFilePath); GetObjectResult getResult = QCloudServer.Instance().cosXml.GetObject(getRequest); Assert.True(200 == getResult.httpCode); // 开始请求上传时 QR code 识别 PutObjectRequest request = new PutObjectRequest(bucket, key, srcPath); JObject o = new JObject(); // 不返回原图 o["is_pic_info"] = 1; JArray rules = new JArray(); JObject rule = new JObject(); rule["bucket"] = bucket; rule["fileid"] = "qrcode.jpg"; //处理参数,规则参见:https://cloud.tencent.com/document/product/460/37513 rule["rule"] = "QRcode/cover/0"; rules.Add(rule); o["rules"] = rules; string ruleString = o.ToString(Formatting.None); request.SetRequestHeader("Pic-Operations", ruleString); //执行请求 PutObjectResult result = QCloudServer.Instance().cosXml.PutObject(request); var uploadResult = result.uploadResult; Assert.IsNotEmpty((result.GetResultInfo())); Assert.True(result.IsSuccessful()); Assert.NotNull(uploadResult); Assert.NotNull(uploadResult.originalInfo); Assert.NotNull(uploadResult.originalInfo.ETag); Assert.NotNull(uploadResult.originalInfo.Key); Assert.NotNull(uploadResult.originalInfo.Location); Assert.NotNull(uploadResult.originalInfo.imageInfo.Format); Assert.NotZero(uploadResult.originalInfo.imageInfo.Width); Assert.NotZero(uploadResult.originalInfo.imageInfo.Height); Assert.NotZero(uploadResult.originalInfo.imageInfo.Quality); Assert.NotNull(uploadResult.processResults); Assert.NotZero(uploadResult.processResults.results.Count); Assert.NotNull(uploadResult.processResults.results[0].ETag); Assert.NotNull(uploadResult.processResults.results[0].Format); Assert.NotNull(uploadResult.processResults.results[0].Key); Assert.NotNull(uploadResult.processResults.results[0].Location); Assert.NotZero(uploadResult.processResults.results[0].Quality); Assert.NotZero(uploadResult.processResults.results[0].Size); Assert.AreEqual(uploadResult.processResults.results[0].CodeStatus, 1); Assert.NotNull(uploadResult.processResults.results[0].QRcodeInfo); Assert.NotNull(uploadResult.processResults.results[0].QRcodeInfo.CodeUrl); Assert.NotNull(uploadResult.processResults.results[0].QRcodeInfo.CodeLocation); Assert.NotNull(uploadResult.processResults.results[0].QRcodeInfo.CodeLocation.Point); Assert.True(uploadResult.processResults.results[0].QRcodeInfo.CodeLocation.Point.Count > 0); QRCodeRecognitionRequest rRequest = new QRCodeRecognitionRequest(bucket, key, 0); QRCodeRecognitionResult rResult = QCloudServer.Instance().cosXml.QRCodeRecognition(rRequest); Assert.IsNotEmpty((rResult.GetResultInfo())); Assert.True(rResult.IsSuccessful()); Assert.NotNull(rResult.recognitionResult); Assert.NotNull(rResult.recognitionResult.QRcodeInfo); Assert.Null(rResult.recognitionResult.ResultImage); Assert.AreEqual(rResult.recognitionResult.CodeStatus, 1); Assert.NotNull(rResult.recognitionResult.QRcodeInfo.CodeLocation); Assert.NotNull(rResult.recognitionResult.QRcodeInfo.CodeUrl); Assert.NotNull(rResult.recognitionResult.QRcodeInfo.CodeLocation.Point); Assert.True(rResult.recognitionResult.QRcodeInfo.CodeLocation.Point.Count > 0); // with cover rRequest = new QRCodeRecognitionRequest(bucket, key, 1); rResult = QCloudServer.Instance().cosXml.QRCodeRecognition(rRequest); Assert.IsNotEmpty((rResult.GetResultInfo())); Assert.True(rResult.IsSuccessful()); Assert.NotNull(rResult.recognitionResult); Assert.NotNull(rResult.recognitionResult.QRcodeInfo); Assert.NotNull(rResult.recognitionResult.ResultImage); Assert.AreEqual(rResult.recognitionResult.CodeStatus, 1); Assert.NotNull(rResult.recognitionResult.QRcodeInfo.CodeLocation); Assert.NotNull(rResult.recognitionResult.QRcodeInfo.CodeUrl); Assert.NotNull(rResult.recognitionResult.QRcodeInfo.CodeLocation.Point); Assert.True(rResult.recognitionResult.QRcodeInfo.CodeLocation.Point.Count > 0); }