Esempio n. 1
0
        public void init()
        {
            string region = "ap-guangzhou";

            CosXmlConfig config = new CosXmlConfig.Builder()
                                  .SetRegion(region)
                                  .SetDebugLog(true)
                                  .SetConnectionLimit(512)
                                  .Build();

            QCloudCredentialProvider qCloudCredentialProvider = new DefaultSessionQCloudCredentialProvider(
                "AKIDLT2qvPSOSRq5eM2TR11daHYBfT1rl8fuWgAJhtbo3eFwcbpFnZHAYkgpaFrzvtq4",
                "i19oUWRIvvpqGpiUgwqa3wufzSbDPyaxv0JYArSQFMc=",
                1597907089,
                "YiPWtzGhVPG5HQlOLQdxZrxHOitu1JXL903fda3a64f28616997f861116b2d7d1EyG_RmvCKqArCLtOXxKv9MGtugt4lPcUbESOTHdhmhEyMYgnPpJSLpbQoKPYzg7WwwvjjXqOKQvs_I9iCHyaBXJu_LToqeuQfO4NFpos8I_NWBKxg23xFpvuXHXJ7kDuyudwu7qInonvJpoXAnb_J-7rMY94aVWSg6kolryvO-x5_C3cBa1fIiKTrwkRP4keh0g3_asIwP99DA-WASJ147C_NsZl9fdTlWEBnIeQqB7uRHAZkF-_f03-fBYJofeYGe7FArrfai4_AO57QbTwacfzHk2s-43WuCIhoLud_-k"
                );

            cosXml = new CosXmlServer(config, qCloudCredentialProvider);

            transferManager = new TransferManager(cosXml, new TransferConfig());

            smallFileSrcPath = QCloudServer.CreateFile(TimeUtils.GetCurrentTime(TimeUnit.SECONDS) + ".txt", 1024 * 1024 * 1);
            bigFileSrcPath   = QCloudServer.CreateFile(TimeUtils.GetCurrentTime(TimeUnit.SECONDS) + ".txt", 1024 * 1024 * 10);
            FileInfo      fileInfo      = new FileInfo(smallFileSrcPath);
            DirectoryInfo directoryInfo = fileInfo.Directory;

            localDir      = directoryInfo.FullName;
            localFileName = "local.txt";
        }
Esempio n. 2
0
        public void globalInit()
        {
            //.cssg-snippet-body-start:[global-init]
            //初始化 CosXmlConfig
            string       appid  = "1253653367";                  //设置腾讯云账户的账户标识 APPID
            string       region = "ap-guangzhou";                //设置一个默认的存储桶地域
            CosXmlConfig config = new CosXmlConfig.Builder()
                                  .SetConnectionTimeoutMs(60000) //设置连接超时时间,单位毫秒,默认45000ms
                                  .SetReadWriteTimeoutMs(40000)  //设置读写超时时间,单位毫秒,默认45000ms
                                  .IsHttps(true)                 //设置默认 HTTPS 请求
                                  .SetAppid(appid)               //设置腾讯云账户的账户标识 APPID
                                  .SetRegion(region)             //设置一个默认的存储桶地域
                                  .SetDebugLog(true)             //显示日志
                                  .Build();                      //创建 CosXmlConfig 对象

            //初始化 QCloudCredentialProvider,COS SDK 中提供了3种方式:永久密钥、临时密钥、自定义
            QCloudCredentialProvider cosCredentialProvider = null;

            //方式1, 永久密钥
            string secretId       = Environment.GetEnvironmentVariable("COS_KEY");    //"云 API 密钥 SecretId";
            string secretKey      = Environment.GetEnvironmentVariable("COS_SECRET"); //"云 API 密钥 SecretKey";
            long   durationSecond = 600;                                              //每次请求签名有效时长,单位为秒

            cosCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond);

            //方式2, 临时密钥
            string tmpSecretId   = Environment.GetEnvironmentVariable("COS_KEY");    //"临时密钥 SecretId";
            string tmpSecretKey  = Environment.GetEnvironmentVariable("COS_SECRET"); //"临时密钥 SecretKey";
            string tmpToken      = "COS_TOKEN";                                      //"临时密钥 token";
            long   tmpExpireTime = 1546862502;                                       //临时密钥有效截止时间

            cosCredentialProvider = new DefaultSessionQCloudCredentialProvider(tmpSecretId, tmpSecretKey,
                                                                               tmpExpireTime, tmpToken);

            //初始化 CosXmlServer
            CosXmlServer cosXml = new CosXmlServer(config, cosCredentialProvider);
            //.cssg-snippet-body-end
        }
Esempio n. 3
0
        private async Task <int> DoUploadAction(ApplyUploadResponse applyResp, VodUploadRequest req)
        {
            string[] fields   = applyResp.StorageBucket.Split('-');
            string   cosAppId = fields[fields.Length - 1];

            CosXmlConfig config = new CosXmlConfig.Builder()
                                  .SetAppid(cosAppId)
                                  .SetRegion(applyResp.StorageRegion)
                                  .SetDebugLog(false)
                                  .SetConnectionLimit(512)
                                  .Build();
            DefaultSessionQCloudCredentialProvider qCloudCredentialProvider = new DefaultSessionQCloudCredentialProvider(applyResp.TempCertificate.SecretId, applyResp.TempCertificate.SecretKey,
                                                                                                                         (long)applyResp.TempCertificate.ExpiredTime, applyResp.TempCertificate.Token);
            CosXmlServer cosXml = new CosXmlServer(config, qCloudCredentialProvider);

            await MultiUpload(cosXml, applyResp.StorageBucket, applyResp.MediaStoragePath, req.MediaFilePath);

            if (!string.IsNullOrEmpty(req.CoverFilePath))
            {
                await MultiUpload(cosXml, applyResp.StorageBucket, applyResp.CoverStoragePath, req.CoverFilePath);
            }
            return(0);
        }
Esempio n. 4
0
 public static void testCAM(string secretId, string secretKey, long expire, string token)
 {
     DefaultSessionQCloudCredentialProvider defaultSessionCredentials = new DefaultSessionQCloudCredentialProvider(secretId, secretKey, expire, token);
 }
        public static void testCAM(string secretId, string secretKey)
        {
            DefaultSessionQCloudCredentialProvider defaultSessionCredentials = new DefaultSessionQCloudCredentialProvider();

            defaultSessionCredentials.SetQCloudCredential(secretId, secretKey);
        }