产品动态
产品公告

dependencies {...// 增加此行implementation 'com.qcloud.cos:quic:1.5.46'}
String region = "ap-beijing"; // 您的存储桶地域String eoDomain = "exampledomain.com"; // eo 加速域名CosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder().setRegion(region).setHost(eoDomain) // 配置加速域名.addNoSignHeaders("Host") // EO 转发请求时 host 会变化,此处需要避免 host 签名.enableQuic(true) // 开启 QUIC.builder();CosXmlService cosXmlService = new CosXmlService(context, cosXmlServiceConfig,credentialProvider);
pod 'QCloudQuic'
NSString * eoDomain = @"exampledomain.com";QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];configuration.enableQuic = YES; // 开启 Quicconfiguration.appID = @"appId"; // 设置 APPIdconfiguration.signatureProvider = self;QCloudCOSXMLEndPoint* endpoint = [[QCloudCOSXMLEndPoint alloc] initWithLiteralURL:[NSURL URLWithString:eoDomain]]; // 配置加速域名endpoint.useHTTPS = YES; // 使用 HTTPSconfiguration.endpoint = endpoint;
String region = "ap-beijing"; // 您的存储桶地域String eoDomain = "exampledomain.com"; // eo 加速域名// 激进策略CosXmlServiceConfig.RequestNetworkStrategy aggressiveStrategy = CosXmlServiceConfig.RequestNetworkStrategy.Aggressive;// 保守策略CosXmlServiceConfig.RequestNetworkStrategy conservativeStrategy = CosXmlServiceConfig.RequestNetworkStrategy.Conservative;CosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder().setRegion(region).setHost(eoDomain) // 配置加速域名.addNoSignHeaders("Host") // EO 转发请求时 host 会变化,此处需要避免 host 签名.enableQuic(true) // 开启 QUIC.setNetworkSwitchStrategy(aggressiveStrategy) // 配置切换策略为激进策略//.setNetworkSwitchStrategy(conservativeStrategy) // 配置切换策略为保守策略.builder();CosXmlService cosXmlService = new CosXmlService(context, cosXmlServiceConfig,credentialProvider);
// 任何 CosXmlRequest 都支持这种方式,例如上传 PutObjectRequest、下载 GetObjectRequest、删除 DeleteObjectRequest 等// 以下用上传进行示例PutObjectRequest putRequest = new PutObjectRequest("examplebucket-1250000000", "exampleobject.txt", "本地文件路径");// 自定义配置 QUIC 协议putRequest.setNetworkType(CosXmlRequest.RequestNetworkType.QUIC);// 自定义配置默认的 HTTPS 协议// putRequest.setNetworkType(CosXmlRequest.RequestNetworkType.OKHTTP);// 初始化 TransferConfig,这里使用默认配置,如果需要定制,请参考 SDK 接口文档TransferConfig transferConfig = new TransferConfig.Builder().build();// 初始化 TransferManagerTransferManager transferManager = new TransferManager(cosXmlService, transferConfig);COSXMLUploadTask uploadTask = transferManager.upload(putRequest, null);
NSString * eoDomain = @"exampledomain.com";QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];configuration.appID = @"appId"; // 设置 APPIDconfiguration.signatureProvider = self;QCloudCOSXMLEndPoint* endpoint = [[QCloudCOSXMLEndPoint alloc] initWithLiteralURL:[NSURL URLWithString:eoDomain]]; // 设置加速域名endpoint.useHTTPS = YES; // 使用 https// 配置加速域名configuration.endpoint = endpoint;// 配置切换策略为激进策略configuration.networkStrategy = QCloudRequestNetworkStrategyAggressive;// 配置切换策略为保守策略// configuration.networkStrategy = QCloudRequestNetworkStrategyConservative;// 开启 QUICconfiguration.enableQuic = YES;[QCloudCOSXMLService registerDefaultCOSXMLWithConfiguration:configuration];[QCloudCOSTransferMangerService registerDefaultCOSTransferMangerWithConfiguration:configuration];
- (void) signatureWithFields:(QCloudSignatureFields*)filedsrequest:(QCloudBizHTTPRequest*)requesturlRequest:(NSMutableURLRequest*)urlRequstcompelete:(QCloudHTTPAuthentationContinueBlock)continueBlock{//这里同步从后台服务器获取临时密钥,强烈建议将获取临时密钥的逻辑放在这里,最大程度上保证密钥的可用性//...QCloudCredential* credential = [QCloudCredential new];// 临时密钥 SecretId// sercret_id 替换为用户的 SecretId,登录访问管理控制台查看密钥,https://console.tencentcloud.com/cam/capicredential.secretID = @"SECRETID";// 临时密钥 SecretKey// sercret_key替换为用户的 SecretKey,登录访问管理控制台查看密钥,https://console.tencentcloud.com/cam/capicredential.secretKey = @"SECRETKEY";// 临时密钥 Token// 如果使用永久密钥不需要填入 token,如果使用临时密钥需要填入,临时密钥生成和使用指引参见 https://www.tencentcloud.com/document/product/436/14048?from_cn_redirect=1credential.token = @"TOKEN";/** 强烈建议返回服务器时间作为签名的开始时间, 用来避免由于用户手机本地时间偏差过大导致的签名不正确(参数 startTime 和 expiredTime 单位为秒)*/credential.startDate = [NSDate dateWithTimeIntervalSince1970:startTime]; // 单位是秒credential.expirationDate = [NSDate dateWithTimeIntervalSince1970:expiredTime]];// 单位是秒QCloudAuthentationV5Creator* creator = [[QCloudAuthentationV5Creator alloc]initWithCredential:credential];// 设置需要参与签名的 Header,不包含 Host 即可。creator.shouldSignedList = @[@"Cache-Control", @"Content-Disposition", @"Content-Encoding", @"Content-Length", @"Content-MD5", @"Content-Type", @"Expect", @"Expires", @"If-Match" , @"If-Modified-Since" , @"If-None-Match" , @"If-Unmodified-Since" , @"Origin" , @"Range" , @"transfer-encoding",@"Pic-Operations",@"ci-process"];// 注意 这里不要对 urlRequst 进行 copy 以及 mutableCopy 操作QCloudSignature *signature = [creator signatureForData:urlRequst];continueBlock(signature, nil);}
QCloudPutObjectRequest* put = [QCloudPutObjectRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在 COS 控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = @"exampleobject";// 文件内容,可以传入NSData*或者NSURL*类型的变量put.body = [@"testFileContent" dataUsingEncoding:NSUTF8StringEncoding];// 自定义配置 QUIC 协议put.networkType = QCloudRequestNetworkQuic;[put setFinishBlock:^(id result, NSError *error) {// result 包含响应的 header 信息// 获取文件 crc64NSString * crc64 = [[result __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSXMLService defaultCOSXML] PutObject:put];
文档反馈