private async Task <ApplyUploadResponse> DoApplyRequest(VodClient client, VodUploadRequest req) { req.MediaType = System.IO.Path.GetExtension(req.MediaFilePath).Substring(1); req.MediaName = System.IO.Path.GetFileName(req.MediaFilePath); if (req.CoverFilePath != null && req.CoverFilePath != "") { req.CoverType = System.IO.Path.GetExtension(req.CoverFilePath).Substring(1); } TencentCloudSDKException err = null; for (int i = 0; i < retryTime; i++) { try { ApplyUploadResponse rsp = await client.ApplyUpload(req); return(rsp); } catch (TencentCloudSDKException exception) { if (exception.RequestId == "") { err = exception; continue; } throw exception; } } throw err; }
public async Task <VodUploadResponse> Upload(string region, VodUploadRequest req) { CheckRequest(region, req); TencentCloud.Common.Credential cred = new TencentCloud.Common.Credential { SecretId = SecretId, SecretKey = SecretKey }; VodClient vodClient = new VodClient(cred, region); ApplyUploadResponse applyResp = await DoApplyRequest(vodClient, req); //Console.WriteLine(AbstractModel.ToJsonString(applyResp)); await DoUploadAction(applyResp, req); CommitUploadResponse commitResp = await DoCommitRequest(vodClient, applyResp); //Console.WriteLine(AbstractModel.ToJsonString(commitResp)); VodUploadResponse rsp = AbstractModel.FromJsonString <VodUploadResponse>(AbstractModel.ToJsonString(commitResp)); return(rsp); }
private async Task <CommitUploadResponse> DoCommitRequest(VodClient client, ApplyUploadResponse applyResp) { CommitUploadRequest commitReq = new CommitUploadRequest(); commitReq.VodSessionKey = applyResp.VodSessionKey; TencentCloudSDKException err = null; for (int i = 0; i < retryTime; i++) { try { return(await client.CommitUpload(commitReq)); } catch (TencentCloudSDKException exception) { if (exception.RequestId == "") { err = exception; continue; } throw exception; } } throw err; }
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); }