产品动态
产品公告


String region = "ap-beijing"; // 您的存储桶地域CosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder().setRegion(region).setAccelerate(true) // 使用 COS 全球加速域名.builder();CosXmlService cosXmlService = new CosXmlService(context, cosXmlServiceConfig,credentialProvider);
QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];configuration.appID = @"appId"; // 设置 APP IDconfiguration.signatureProvider = self;QCloudCOSXMLEndPoint *endpoint = [[QCloudCOSXMLEndPoint alloc]init];endpoint.suffix = @"cos.accelerate.myqcloud.com"; // 设置全球加速域名endpoint.useHTTPS = YES; // 使用 httpsconfiguration.endpoint = endpoint;
var cos = new COS({UseAccelerate: true, // 指定 true,使用全球加速域名请求});
String region = "ap-beijing"; // 您的存储桶地域String eoDomain = "exampledomain.com"; // eo 加速域名CosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder().setRegion(region).setHost(eoDomain) // 配置加速域名.addNoSignHeaders("Host") // EO 转发请求时 host 会变化,此处需要避免 host 签名.builder();CosXmlService cosXmlService = new CosXmlService(context, cosXmlServiceConfig,credentialProvider);
NSString * eoDomain = @"exampledomain.com";QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];configuration.appID = @"appId"; // 设置 APP IDconfiguration.signatureProvider = self;QCloudCOSXMLEndPoint* endpoint = [[QCloudCOSXMLEndPoint alloc] initWithLiteralURL:[NSURL URLWithString:eoDomain]]; // 设置加速域名endpoint.useHTTPS = YES; // 使用 httpsconfiguration.endpoint = endpoint;

var cos = new COS({Domain: 'edgeone.example.com', // 指定请求域名为 EdgeOne 的域名。ForceSignHost: false, // 由于实际请求的域名和回源域名不一致,需要指定不签 Host 头。Host});
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 签名.setNetworkSwitchStrategy(aggressiveStrategy) // 配置切换策略为激进策略//.setNetworkSwitchStrategy(conservativeStrategy) // 配置切换策略为保守策略.builder();CosXmlService cosXmlService = new CosXmlService(context, cosXmlServiceConfig,credentialProvider);
// 任何CosXmlRequest都支持这种方式,例如上传PutObjectRequest、下载GetObjectRequest、删除DeleteObjectRequest等// 以下用上传进行示例PutObjectRequest putRequest = new PutObjectRequest("examplebucket-1250000000", "exampleobject.txt", "本地文件路径");String eoDomain = "exampledomain.com"; // eo 加速域名// 自定义配置具体的请求网络线路,设置null则走默认的COS域名线路putRequest.setHost(eoDomain);// 初始化 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"; // 设置 APP IDconfiguration.signatureProvider = self;QCloudCOSXMLEndPoint* endpoint = [[QCloudCOSXMLEndPoint alloc] initWithLiteralURL:[NSURL URLWithString:eoDomain]]; // 设置加速域名endpoint.useHTTPS = YES; // 使用 https// 配置加速域名configuration.endpoint = endpoint;// 配置切换策略为激进策略configuration.networkStrategy = QCloudRequestNetworkStrategyAggressive;// 配置切换策略为保守策略// configuration.networkStrategy = QCloudRequestNetworkStrategyConservative;[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];// 设置自定义域名NSString * eoDomain = @"exampledomain.com";QCloudCOSXMLEndPoint* endpoint = [[QCloudCOSXMLEndPoint alloc] initWithLiteralURL:[NSURL URLWithString:eoDomain]]; // 设置加速域名put.endpoint = endpoint;// 存储桶名称,由 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];[put setFinishBlock:^(id result, NSError *error) {// result 包含响应的 header 信息// 获取文件 crc64NSString * crc64 = [[result __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSXMLService defaultCOSXML] PutObject:put];
文档反馈