.NET SDK 是否支持下载对象到内存?
.NET SDK 预签名URL过期时间如何设置?
预签名的过期问题通过签名时间和密钥过期时间两项控制,两个时间不同时由最近过期时间决定。
AK 密钥过期时间在 QCloudCredentialProvider 初始化时决定,例如 durationSecond 变量的控制:
public class DownloadObject{private CosXml cosXml;private void InitCosXml(){string region = Environment.GetEnvironmentVariable("COS_REGION");CosXmlConfig config = new CosXmlConfig.Builder().SetRegion(region).Build();string secretId = Environment.GetEnvironmentVariable("SECRET_ID");string secretKey = Environment.GetEnvironmentVariable("SECRET_KEY");long durationSecond = 600; // AK 密钥过期时间QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond);this.cosXml = new CosXmlServer(config, qCloudCredentialProvider);}}
Sign 签名的过期时间由 PreSignatureStruct 对象的 signDurationSecond 成员控制决定:
public void GetPreSignDownloadUrl(){try{PreSignatureStruct preSignatureStruct = new PreSignatureStruct();//在此省略其余设置preSignatureStruct.signDurationSecond = 600; // Sign 签名的过期时间string requestSignURL = cosXml.GenerateSignURL(preSignatureStruct);Console.WriteLine(requestSignURL);}catch (COSXML.CosException.CosClientException clientEx){Console.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){Console.WriteLine("CosServerException: " + serverEx.GetInfo());}}