dependencies {...// Add this lineimplementation 'com.qcloud.cos:quic:1.5.46'}
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.enableQuic(true) // Enable QUIC.builder();CosXmlService cosXmlService = new CosXmlService(context, cosXmlServiceConfig,credentialProvider);
pod 'QCloudQuic'
NSString * eoDomain = @"exampledomain.com";QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];configuration.enableQuic = YES; // Enable Quicconfiguration.appID = @"appId"; // Set the APPIdconfiguration.signatureProvider = self;QCloudCOSXMLEndPoint* endpoint = [[QCloudCOSXMLEndPoint alloc] initWithLiteralURL:[NSURL URLWithString:eoDomain]]; // Configure the acceleration domainendpoint.useHTTPS = YES; // Use HTTPSconfiguration.endpoint = endpoint;
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.enableQuic(true) // Enable QUIC.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, upload PutObjectRequest, download GetObjectRequest, delete DeleteObjectRequest, etc.// The following uses upload as an examplePutObjectRequest putRequest = new PutObjectRequest("examplebucket-1250000000", "exampleobject.txt", "Local file path");// Custom configuration for the QUIC protocolputRequest.setNetworkType(CosXmlRequest.RequestNetworkType.QUIC);// Custom configuration for the default HTTPS protocol// putRequest.setNetworkType(CosXmlRequest.RequestNetworkType.OKHTTP);// 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 APPIDconfiguration.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;// Enable QUICconfiguration.enableQuic = YES;[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];// 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];// Custom configuration for the QUIC protocolput.networkType = QCloudRequestNetworkQuic;[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