public void PutObjectACL() { try { PutObjectACLRequest request = new PutObjectACLRequest(bucket, commonKey); //添加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 fullAccount = new COSXML.Model.Tag.GrantAccount(); fullAccount.AddGrantAccount("2832742109", "2832742109"); request.SetXCosReadWrite(fullAccount); //执行请求 PutObjectACLResult result = cosXml.PutObjectACL(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); } }
public static void AsynPutObjectACL(COSXML.CosXml cosXml, string bucket, string key) { QLog.D("XIAO", String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); PutObjectACLRequest request = new PutObjectACLRequest(bucket, key); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //添加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.PutObjectACL(request, delegate(CosResult cosResult) { PutObjectACLResult result = cosResult as PutObjectACLResult; 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 static void PutObjectACL(COSXML.CosXml cosXml, string bucket, string key) { try { PutObjectACLRequest request = new PutObjectACLRequest(bucket, key); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //添加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); //执行请求 PutObjectACLResult result = cosXml.PutObjectACL(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()); } }