
String region = "ap-beijing"; // Your bucket regionCosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder().setRegion(region).setAccelerate(true) // Use the COS global acceleration domain.builder();CosXmlService cosXmlService = new CosXmlService(context, cosXmlServiceConfig,credentialProvider);
QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];configuration.appID = @"appId"; // Set the APP IDconfiguration.signatureProvider = self;QCloudCOSXMLEndPoint *endpoint = [[QCloudCOSXMLEndPoint alloc]init];endpoint.suffix = @"cos.accelerate.myqcloud.com"; // Set the global acceleration domainendpoint.useHTTPS = YES; // Use httpsconfiguration.endpoint = endpoint;
var cos = new COS({UseAccelerate: true, // Specify true to use the global acceleration domain for requests});
String region = "ap-beijing"; // Your bucket regionString eoDomain = "exampledomain.com"; // eo acceleration domainCosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder().setRegion(region).setHost(eoDomain) // Configure the acceleration domain.addNoSignHeaders("Host") // When EO forwards requests, the host may change; avoid signing the host here.builder();CosXmlService cosXmlService = new CosXmlService(context, cosXmlServiceConfig,credentialProvider);
NSString * eoDomain = @"exampledomain.com";QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];configuration.appID = @"appId"; // Set the APP IDconfiguration.signatureProvider = self;QCloudCOSXMLEndPoint* endpoint = [[QCloudCOSXMLEndPoint alloc] initWithLiteralURL:[NSURL URLWithString:eoDomain]]; // Set the acceleration domainendpoint.useHTTPS = YES; // Use httpsconfiguration.endpoint = endpoint;

var cos = new COS({Domain: 'edgeone.example.com', // Specify the request domain as the EdgeOne domain.ForceSignHost: false, // Since the actual request domain differs from the origin domain, avoid signing the Host header.Host});
String region = "ap-beijing"; // Your bucket regionString eoDomain = "exampledomain.com"; // eo acceleration domain// Aggressive policyCosXmlServiceConfig.RequestNetworkStrategy aggressiveStrategy = CosXmlServiceConfig.RequestNetworkStrategy.Aggressive;// Conservative policyCosXmlServiceConfig.RequestNetworkStrategy conservativeStrategy = CosXmlServiceConfig.RequestNetworkStrategy.Conservative;CosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder().setRegion(region).setHost(eoDomain) // Configure the acceleration domain.addNoSignHeaders("Host") // When EO forwards requests, the host may change; avoid signing the host here.setNetworkSwitchStrategy(aggressiveStrategy) // Configure the switching policy as aggressive policy//.setNetworkSwitchStrategy(conservativeStrategy) // Configure the switching policy as conservative policy.builder();CosXmlService cosXmlService = new CosXmlService(context, cosXmlServiceConfig,credentialProvider);
// Any CosXmlRequest supports this method, for example, uploading PutObjectRequest, downloading GetObjectRequest, deleting DeleteObjectRequest, etc.// The following uses upload as an examplePutObjectRequest putRequest = new PutObjectRequest("examplebucket-1250000000", "exampleobject.txt", "Local file path");String eoDomain = "exampledomain.com"; // eo acceleration domain// Customize the request network line for specific requests; if set to null, use the default COS domain lineputRequest.setHost(eoDomain);// Initialize TransferConfig with the default configuration. If you need to customize it, see the SDK API documentation.TransferConfig transferConfig = new TransferConfig.Builder().build();// Initialize TransferManagerTransferManager transferManager = new TransferManager(cosXmlService, transferConfig);COSXMLUploadTask uploadTask = transferManager.upload(putRequest, null);
NSString * eoDomain = @"exampledomain.com";QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];configuration.appID = @"appId"; // Set the APP IDconfiguration.signatureProvider = self;QCloudCOSXMLEndPoint* endpoint = [[QCloudCOSXMLEndPoint alloc] initWithLiteralURL:[NSURL URLWithString:eoDomain]]; // Set the acceleration domainendpoint.useHTTPS = YES; // Use https// Configure the acceleration domainconfiguration.endpoint = endpoint;// Configure the switch policy as the aggressive policyconfiguration.networkStrategy = QCloudRequestNetworkStrategyAggressive;// Configure the switch policy as the conservative policy// configuration.networkStrategy = QCloudRequestNetworkStrategyConservative;[QCloudCOSXMLService registerDefaultCOSXMLWithConfiguration:configuration];[QCloudCOSTransferMangerService registerDefaultCOSTransferMangerWithConfiguration:configuration];
- (void) signatureWithFields:(QCloudSignatureFields*)filedsrequest:(QCloudBizHTTPRequest*)requesturlRequest:(NSMutableURLRequest*)urlRequstcompelete:(QCloudHTTPAuthentationContinueBlock)continueBlock{// Synchronously obtain the temporary key from the backend server. It is strongly recommended to place the logic for obtaining the temporary key here to maximize the availability of the key.//...QCloudCredential* credential = [QCloudCredential new];// Temporary key SecretId// Replace sercret_id with your SecretId. Log in to the CAM console to view keys: https://console.tencentcloud.com/cam/capicredential.secretID = @"SECRETID";// Temporary key SecretKey// Replace sercret_key with your SecretKey. Log in to the CAM console to view keys: https://console.tencentcloud.com/cam/capicredential.secretKey = @"SECRETKEY";// Temporary key Token// If using a permanent key, you do not need to provide a token. If using a temporary key, you need to provide one. For instructions on generating and using temporary keys, see https://www.tencentcloud.com/document/product/436/14048?from_cn_redirect=1credential.token = @"TOKEN";/** It is strongly recommended to use the server time as the start time for the signature to avoid signature errors caused by significant deviations in the user's local device time (parameters startTime and expiredTime are in seconds).*/credential.startDate = [NSDate dateWithTimeIntervalSince1970:startTime]; // Unit: secondscredential.expirationDate = [NSDate dateWithTimeIntervalSince1970:expiredTime]]; // Unit: secondsQCloudAuthentationV5Creator* creator = [[QCloudAuthentationV5Creator alloc]initWithCredential:credential];// Set the headers to be included in the signature, excluding 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"];// Note: Do not perform copy or mutableCopy operations on the URLRequest here.QCloudSignature *signature = [creator signatureForData:urlRequst];continueBlock(signature, nil);}
QCloudPutObjectRequest* put = [QCloudPutObjectRequest new];// Set the custom domainNSString * eoDomain = @"exampledomain.com";QCloudCOSXMLEndPoint* endpoint = [[QCloudCOSXMLEndPoint alloc] initWithLiteralURL:[NSURL URLWithString:eoDomain]]; // Set the acceleration domainput.endpoint = endpoint;// Bucket name, which consists of BucketName-Appid, can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketput.bucket = @"examplebucket-1250000000";// Object key, which is the full path of the object on COS. If including a directory, the format should be "video/xxx/movie.mp4"put.object = @"exampleobject";// File content. You can pass in a variable of type NSData* or NSURL*put.body = [@"testFileContent" dataUsingEncoding:NSUTF8StringEncoding];[put setFinishBlock:^(id result, NSError *error) {// result contains the response header information// Obtain the file crc64NSString * crc64 = [[result __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSXMLService defaultCOSXML] PutObject:put];
Feedback