The API documentation contains a detailed API list and usage examples, which are written for those who completed initialization. It is recommended to use Command+F to find the API, check its description, and apply in your project.
If you need more features, or do not understand what the returned parameters mean, you are advised to view the comments in the code using three finger drag, Force-touch, or hovering over the variable and pressing Control+Command+D.
This section describes the best practices of some common operations, which are available after you complete the initialization according to Getting Started.
See the Upload a file section in Getting Started.
Multipart upload is used to upload a file larger than 1 MB. That is, split the file into multiple parts with each holding a size of 1 MB, and then upload these parts (4 at most) in parallel. Resuming upload from breakpoint is implemented on the basis that the uploaded parts are stored in the backend server.
During multipart upload, resumeData for resuming upload is generated after you initialize multipart upload or cancel the upload. This is used to generate another upload request for resuming upload. The following example shows how to get ResumeData:
QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];
//···Set some parameters for upload
put.initMultipleUploadFinishBlock = ^(QCloudInitiateMultipartUploadResult * multipleUploadInitResult, QCloudCOSXMLUploadObjectResumeData resumeData) {
//Call back the block after you initialize multipart upload, in which you can obtain resumeData for generating a multipart upload request
QCloudCOSXMLUploadObjectRequest* request = [QCloudCOSXMLUploadObjectRequest requestWithRequestData:resumeData];
};
[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];
//···When initialization is completed and upload is not completed
NSError* error;
//The following shows how resumeData is generated after the user cancels the upload
resumeData = [put cancelByProductingResumeData:&error];
if (resumeData) {
QCloudCOSXMLUploadObjectRequest* request = [QCloudCOSXMLUploadObjectRequest requestWithRequestData:resumeData];
}
//The generated request for resuming upload can be directly uploaded
[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:request];
Note: The multipart upload uses the serial mode where parts must be uploaded in sequence. Under the following circumstances, resuming upload from breakpoint cannot be used.
See the Download a file section in Getting Started.
Initialize a QCloudCOSXMLCopyObjectRequest object, and then call CopyObject of QCloudCOSTransferMangerService. Note that multipart copy is automatically used for large files, but users will not be aware of this process.
For cross-origin replication, the region of transferManager must be the same as that of the bucket.
QCloudCOSXMLCopyObjectRequest* request = [[QCloudCOSXMLCopyObjectRequest alloc] init];
request.bucket = @"Destination bucket";
request.object = @"Destination file name";
request.sourceBucket = @"File source bucket. Public read or access to the current account is required";
request.sourceObject = @"Source file name";
request.sourceAPPID = @"Source APPID";
request.sourceRegion= @"Source region";
[request setFinishBlock:^(QCloudCopyObjectResult* result, NSError* error) {
//Complete callback
if (nil == error) {
//Successful
}
}];
//For cross-origin replication, the region of transferManager must be the same as that of the bucket.
[[QCloudCOSTransferMangerService defaultCOSTransferManager] CopyObject:request];
This API (Get Service) is used to obtain all Bucket lists of the requester.
Parameter Name | Description | Type |
---|---|---|
owner | Bucket owner information | QCloudOwner * |
buckets | All bucket information | NSArray<QCloudBucket*> * |
QCloudGetServiceRequest* request = [[QCloudGetServiceRequest alloc] init];
[request setFinishBlock:^(QCloudListAllMyBucketsResult* result, NSError* error) {
//Process after callback is completed
}];
[[QCloudCOSXMLService defaultCOSXML] GetService:request];
You can generate a pre-signed URL from the SDK or server, and then upload, download or perform other operations as needed.
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket using a pre-signed request | NSString* | Yes |
object | Object using a pre-signed request. ObjectKey is the unique identifier of an object in a bucket. For example, in the object's access domain name "bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg", the key is "doc1/pic1.jpg". For more information, see Object Description. | NSString* | Yes |
HTTPMethod | HTTP method of the request using a pre-signed URL. Valid values (case-sensitive): @"GET", @"PUT", @"POST" and @"DELETE". | NSString* | Yes |
contentType | This parameter is available when the request using a pre-signed URL has this header. | NSString* | No |
contentMD5 | This parameter is available when the request using a pre-signed URL has this header. | NSString* | No |
Note: To set the header or URL parameter of the request using a pre-signed URL, do the following:
/**
Add the header of the request using a pre-signed request
@param value HTTP header value
@param requestHeader HTTP header key
*/
- (void)setValue:(NSString * _Nullable)value forRequestHeader:(NSString * _Nullable)requestHeader;
/**
Add the URL parameter of the request using a pre-signed request
@param value Parameter value
@param requestParameter Parameter key
*/
- (void)setValue:(NSString * _Nullable)value forRequestParameter:(NSString *_Nullable)requestParameter;
QCloudGetPresignedURLRequest* getPresignedURLRequest = [[QCloudGetPresignedURLRequest alloc] init];
getPresignedURLRequest.bucket = self.bucket;
getPresignedURLRequest.HTTPMethod = @"GET";
getPresignedURLRequest.object = @"testUploadWithPresignedURL";
[getPresignedURLRequest setFinishBlock:^(QCloudGetPresignedURLResult * _Nonnull result, NSError * _Nonnull error) {
if (nil == error) {
NSString* presignedURL = result.presienedURL;
}
}
[[QCloudCOSXMLService defaultCOSXML] getPresignedURL:getPresignedURLRequest];
The following example shows how to download with a pre-signed URL.
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"Pre-signed URL"]];
request.HTTPMethod = @"GET";
request.HTTPBody = [@"File content" dataUsingEncoding:NSUTF8StringEncoding];
[[[NSURLSession sharedSession] downloadTaskWithRequest:request completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSInteger statusCode = [(NSHTTPURLResponse*)response statusCode];
}] resume];
Before using COS, you need to create a bucket under the specific account for use and management of objects, and define the region of the bucket. The creator of the bucket is the owner of the bucket by default. The bucket access permission is Private Read/Write by default if not otherwise specified upon creation. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | The name of the bucket to be created, which can be viewed in the COS V5 Console. Note that the bucket name can only consist of numbers and lowercase letters with a length limited to 40 characters; otherwise, the creation will fail. | NSString * | Yes |
accessControlList | Defines the ACL attribute of a bucket. Valid values: private, public-read-write, public-read; Default: private | NSString * | No |
grantRead | Grants read permission to the authorized user. Format: id=" ",id=" ". For authorization to a subaccount, id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>"; for authorization to the root account, id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>", where OwnerUin refers to the ID of the root account and SubUin refers to the ID of the subaccount. | NSString * | No |
grantWrite | Grants write permission to the authorized user. The format is the same as above. | NSString * | No |
grantFullControl | Grants read and write permissions to the authorized user. The format is the same as above. | NSString * | No |
QCloudPutBucketRequest* request = [QCloudPutBucketRequest new];
request.bucket = @"bucketname-appid"; //additional actions after finishing
[request setFinishBlock:^(id outputObject, NSError* error) {
}];
[[QCloudCOSXMLService defaultCOSXML] PutBucket:request];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before bucket operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudGetBucketRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
prefix | Prefix match, used to specify the prefix address of the returned file. | NSString * | No |
delimiter | Delimiter is a sign. If Prefix exists, the same paths between Prefix and delimiter are grouped as the same type and defined as Common Prefix, and then all Common Prefixes are listed. If Prefix does not exist, the listing process starts from the beginning of the path. It can be considered as an ending symbol. For example, if you want a string to end with A, set delimiter to A. | NSString * | No |
encodingType | Indicates the encoding method of the returned value. Available value: url | NSString * | No |
marker | Entries are listed using UTF-8 binary order by default, starting from marker | NSString * | No |
maxKeys | Maximum number of entries returned at a time. Default is 1000. | int | No |
QCloudGetBucketRequest* request = [QCloudGetBucketRequest new];
request.bucket = @“testBucket-123456789”;
request.maxKeys = 1000;
[request setFinishBlock:^(QCloudListBucketResult * result, NSError* error) {
//additional actions after finishing
}];
[[QCloudCOSXMLService defaultCOSXML] GetBucket:request];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before bucket operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudGetBucketACLRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
Parameter Name | Description | Type |
---|---|---|
owner | Bucket owner information | QCloudACLOwner * |
accessControlList | Information of the authorized user and permissions | QCloudAccessControlList * |
QCloudGetBucketACLRequest* getBucketACl = [QCloudGetBucketACLRequest new];
getBucketACl.bucket = @"testbucket-123456789";
[getBucketACl setFinishBlock:^(QCloudACLPolicy * _Nonnull result, NSError * _Nonnull error) {
//QCloudACLPolicy contains Bucket ACL information.
}];
[[QCloudCOSXMLService defaultCOSXML] GetBucketACL:getBucketACl];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before bucket operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudPutBucketACLRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID> , such as testBucket-1253653367 | NSString * | Yes |
accessControlList | Defines the ACL attribute of an object. Valid values: private, public-read-write, public-read; Default: private | NSString * | No |
grantRead | Grants read permission to the authorized user. Format: id=" ",id=" ". For authorization to a subaccount, id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>", for authorization to the root account, id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>", where OwnerUin refers to the ID of the root account and SubUin refers to the ID of the subaccount. |
NSString * | No |
grantWrite | Grants write permission to the authorized user. The format is the same as above. | NSString * | No |
grantFullControl | Grants read and write permissions to the authorized user. The format is the same as above. | NSString * | No |
QCloudPutBucketACLRequest* putACL = [QCloudPutBucketACLRequest new];
NSString* appID = @“Your APPID”;
NSString *ownerIdentifier = [NSString stringWithFormat:@"qcs::cam::uin/%@:uin/%@", appID, appID];
NSString *grantString = [NSString stringWithFormat:@"id=\"%@\"",ownerIdentifier];
putACL.grantFullControl = grantString;
putACL.bucket = @“testBucket-123456789”;
[putACL setFinishBlock:^(id outputObject, NSError *error) {
//error occucs if error != nil
}];
[[QCloudCOSXMLService defaultCOSXML] PutBucketACL:putACL];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before bucket operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudGetBucketCORSRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
Parameter Name | Description | Type |
---|---|---|
rules | The array containing CORS. It is a QCloudCORSRule instance. | NSArray<CloudCORSRule* > * |
Parameter Name | Description | Type |
---|---|---|
identifier | ID of the configuration rule | NSString * |
allowedMethod | Allowed HTTP operations. Enumerated values: GET, PUT, HEAD, POST, DELETE | NSArray<NSString* >* |
allowedOrigin | Allowed access source. The wildcard "*" is supported. Format: protocol://domain name[:port], for example, http://www.qq.com |
NSString * |
allowedHeader | It is used to notify the server about which custom HTTP request headers are allowed for subsequent requests when an OPTIONS request is sent. The wildcard "*" is supported. | NSArray<NSString* > * |
maxAgeSeconds | Configures the valid period of the results obtained by OPTIONS request | int |
exposeHeader | Configures the custom header information that can be received by the browser from the server | NSString * |
QCloudGetBucketCORSRequest* corsReqeust = [QCloudGetBucketCORSRequest new];
corsReqeust.bucket = @"testBucket-123456789";
[corsReqeust setFinishBlock:^(QCloudCORSConfiguration * _Nonnull result, NSError * _Nonnull error) {
//CORS is encapsulated in result.
}];
[[QCloudCOSXMLService defaultCOSXML] GetBucketCORS:corsReqeust];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before bucket operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudPutBucketCORSRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
corsConfiguration | Specific parameter that encapsulates CORS | QCloudCORSConfiguration * | Yes |
Parameter Name | Description | Type |
---|---|---|
rules | The array containing CORS. It is a QCloudCORSRule instance. | NSArray<QCloudCORSRule* > * |
Parameter Name | Description | Type |
---|---|---|
identifier | ID of the configuration rule | NSString * |
allowedMethod | Allowed HTTP operations. Enumerated values: GET, PUT, HEAD, POST, DELETE | NSArray <NSString* > * |
allowedOrigin | Allowed access source. The wildcard "*" is supported. Format: protocol://domain name[:port], for example, http://www.qq.com |
NSString * |
allowedHeader | It is used to notify the server about which custom HTTP request headers are allowed for subsequent requests when an OPTIONS request is sent. The wildcard "*" is supported. | NSArray <NSString * > * |
maxAgeSeconds | Configures the valid period of the results obtained by OPTIONS request | int |
exposeHeader | Configures the custom header information that can be received by the browser from the server | NSString * |
QCloudPutBucketCORSRequest* putCORS = [QCloudPutBucketCORSRequest new];
QCloudCORSConfiguration* cors = [QCloudCORSConfiguration new];
QCloudCORSRule* rule = [QCloudCORSRule new];
rule.identifier = @"sdk";
rule.allowedHeader = @[@"origin",@"host",@"accept",@"content-type",@"authorization"];
rule.exposeHeader = @"ETag";
rule.allowedMethod = @[@"GET",@"PUT",@"POST", @"DELETE", @"HEAD"];
rule.maxAgeSeconds = 3600;
rule.allowedOrigin = @"*";
cors.rules = @[rule];
putCORS.corsConfiguration = cors;
putCORS.bucket = @"testBucket-123456789";
[putCORS setFinishBlock:^(id outputObject, NSError *error) {
if (!error) {
//success
}
}];
[[QCloudCOSXMLService defaultCOSXML] PutBucketCORS:putCORS];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before bucket operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudGetBucketLocationRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
Parameter Name | Description | Type |
---|---|---|
locationConstraint | The region where the bucket resides | NSString* |
QCloudGetBucketLocationRequest* locationReq = [QCloudGetBucketLocationRequest new];
locationReq.bucket = @"testBucket-123456789";
__block QCloudBucketLocationConstraint* location;
[locationReq setFinishBlock:^(QCloudBucketLocationConstraint * _Nonnull result, NSError * _Nonnull error) {
location = result;
}];
[[QCloudCOSXMLService defaultCOSXML] GetBucketLocation:locationReq];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before bucket operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudDeleteBucketCORSRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
QCloudDeleteBucketCORSRequest* deleteCORS = [QCloudDeleteBucketCORSRequest new];
deleteCORS.bucket = @"testBucket-123456789";
[deleteCORS setFinishBlock:^(id outputObject, NSError *error) {
//success if error == nil
}];
[[QCloudCOSXMLService defaultCOSXML] DeleteBucketCORS:deleteCORS];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before bucket operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudListBucketMultipartUploadsRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
prefix | The returned Object key must be prefixed with Prefix. Note that the returned key will still contain Prefix when querying with prefix. | NSString * | No |
delimiter | Delimiter is a sign. If Prefix exists, the same paths between Prefix and delimiter are grouped as the same type and defined as Common Prefix, and then all Common Prefixes are listed. If Prefix does not exist, the listing process starts from the beginning of the path. It can be considered as an ending symbol. For example, if you want a string to end with A, set delimiter to A. | NSString * | No |
encodingType | Indicates the encoding method of the returned value. Available value: url | NSString * | No |
keyMarker | Entries will be listed starting from this key value | NSString * | No |
uploadIDMarker | Entries will be listed starting from this UploadId value | int | No |
maxUploads | Sets the maximum number of multipart returned. Valid values: 1-1000 | int | No |
Parameter Name | Description | Type |
---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * |
prefix | The returned Object key must be prefixed with Prefix. Note that the returned key will still contain Prefix when querying with prefix. | NSString * |
delimiter | Delimiter is a sign. If Prefix exists, the same paths between Prefix and delimiter are grouped as the same type and defined as Common Prefix, and then all Common Prefixes are listed. If Prefix does not exist, the listing process starts from the beginning of the path | NSString * |
encodingType | Indicates the encoding method of the returned value. Available value: url | NSString * |
keyMarker | Entries will be listed starting from this key value | NSString * |
maxUploads | Sets the maximum number of multipart returned. Valid values: 1-1000 | int |
uploads | Information of all multipart upload operations | NSArray* |
QCloudListBucketMultipartUploadsRequest* uploads = [QCloudListBucketMultipartUploadsRequest new];
uploads.bucket = @"testBucket-123456789";
uploads.maxUploads = 100;
__block NSError* resulError;
__block QCloudListMultipartUploadsResult* multiPartUploadsResult;
[uploads setFinishBlock:^(QCloudListMultipartUploadsResult* result, NSError *error) {
multiPartUploadsResult = result;
localError = error;
}];
[[QCloudCOSXMLService defaultCOSXML] ListBucketMultipartUploads:uploads];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem. Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
Head Bucket request is used to determine whether a bucket exists and whether you can access the bucket. Head and Read have the same permission. 200 is returned if the bucket exists; 403 is returned if you cannot access the bucket; and 404 is returned if the bucket does not exist.
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
QCloudHeadBucketRequest* request = [QCloudHeadBucketRequest new];
request.bucket = @"testBucket-123456789";
[request setFinishBlock:^(id outputObject, NSError* error) {
//Set the completion callback. If no error, the bucket can be accessed normally. Otherwise, you can get the specific failure reason by viewing the error code and message.
}];
[[QCloudCOSXMLService defaultCOSXML] HeadBucket:request];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
COS allows you to manage the lifecycle of an object in a bucket by configuring lifecycle. The lifecycle configuration contains one or more rule sets that will be applied to a group of object rules (each rule defines an operation for COS).
These operations are divided into the following two types:
Put Bucket Lifecycle is used to create a new lifecycle configuration for a Bucket. If the Bucket has been configured with a lifecycle, you can use this API to create a new configuration which will overwrite the existing one.
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
lifeCycle | Lifecycle configuration | QCloudLifecycleConfiguration* | Yes |
Parameter Name | Description | Type | Required |
---|---|---|---|
rules | An array describing a collection of rules | NSArray<QCloudLifecycleRule*> * | Yes |
Parameter Name | Description | Type | Required |
---|---|---|---|
identifier | Uniquely identifies a rule. Its length cannot exceed 255 characters. | NSString* | Yes |
filter | Describes the collection of Objects affected by rules | QCloudLifecycleRuleFilter* | |
status | Indicates whether the rule is enabled. Enumerated values: Enabled, Disabled. | QCloudLifecycleStatue | Yes |
abortIncompleteMultipartUpload | Sets the maximum length of time allowed for a continuous multipart upload | QCloudLifecycleAbortIncompleteMultipartUpload | No |
transition | Rule transition attribute, which indicates when an object is transited to Standard_IA etc. | QCloudLifecycleTransition* | No |
expiration | Rule expiration attribute | QCloudLifecycleExpiration* | No |
noncurrentVersionExpiration | Indicates when objects of non-current version expire | QCloudLifecycleExpiration* | No |
noncurrentVersionTransition | Indicates when objects of non-current version are transited to STANDARD_IA etc. | QCloudNoncurrentVersionExpiration* | No |
QCloudPutBucketLifecycleRequest* request = [QCloudPutBucketLifecycleRequest new];
request.bucket = @"Enter bucket name";
__block QCloudLifecycleConfiguration* configuration = [[QCloudLifecycleConfiguration alloc] init];
QCloudLifecycleRule* rule = [[QCloudLifecycleRule alloc] init];
rule.identifier = @"identifier";
rule.status = QCloudLifecycleStatueEnabled;
QCloudLifecycleRuleFilter* filter = [[QCloudLifecycleRuleFilter alloc] init];
filter.prefix = @"0";
rule.filter = filter;
QCloudLifecycleTransition* transition = [[QCloudLifecycleTransition alloc] init];
transition.days = 100;
transition.storageClass = QCloudCOSStorageStandarIA;
rule.transition = transition;
request.lifeCycle = configuration;
request.lifeCycle.rules = @[rule];
[request setFinishBlock:^(id outputObject, NSError* error) {
//Set the completion callback
}];
[[QCloudCOSXMLService defaultCOSXML] PutBucketLifecycle:request];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
Same with QCloudLifecycleConfiguration in the API Put Bucket Lifecycle.
QCloudGetBucketLifecycleRequest* request = [QCloudGetBucketLifecycleRequest new];
request.bucket = @"testBucket-123456789";
[request setFinishBlock:^(QCloudLifecycleConfiguration* result,NSError* error) {
//Set the completion callback
}];
[[QCloudCOSXMLService defaultCOSXML] GetBucketLifecycle:request];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
Same with QCloudLifecycleConfiguration in the API Put Bucket Lifecycle.
QCloudDeleteBucketLifeCycleRequest* request = [[QCloudDeleteBucketLifeCycleRequest alloc ] init];
request.bucket = @"testBucket-123456789";
[request setFinishBlock:^(QCloudLifecycleConfiguration* result, NSError* error) {
//Set the completion callback
}];
[[QCloudCOSXMLService defaultCOSXML] DeleteBucketLifeCycle:request];
This API (Put Bucket Versioning) is used to enable or suspend the bucket version control feature. Note: this is an irreversible API, and cannot be disabled after being enabled.
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
configuration | Version control details | QCloudBucketVersioningConfiguration* | Yes |
Parameter Name | Description | Type | Required |
---|---|---|---|
status | Indicates whether version control is enabled. Enumerated values: Suspended\Enabled. | QCloudCOSBucketVersioningStatus | Yes |
QCloudPutBucketVersioningRequest* request = [[QCloudPutBucketVersioningRequest alloc] init];
request.bucket = @"testBucket-123456789";
QCloudBucketVersioningConfiguration* configuration = [[QCloudBucketVersioningConfiguration alloc] init];
request.configuration = configuration;
configuration.status = QCloudCOSBucketVersioningStatusEnabled;
[request setFinishBlock:^(id outputObject, NSError* error) {
//Set the completion callback
}];
[[QCloudCOSXMLService defaultCOSXML] PutBucketVersioning:request];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
Parameter Name | Description | Type |
---|---|---|
status | Indicates whether version control is enabled. Enumerated values: Suspended\Enabled. | QCloudCOSBucketVersioningStatus |
QCloudGetBucketVersioningRequest* request = [[QCloudGetBucketVersioningRequest alloc] init];
request.bucket = @"testBucket-123456789";
[request setFinishBlock:^(QCloudBucketVersioningConfiguration* result, NSError* error) {
//Set the completion callback
}];
[[QCloudCOSXMLService defaultCOSXML] GetBucketVersioning:request];
Put Bucket Replication request is used to add replication configuration to the bucket for which the version control is enabled. If the bucket already has a replication configuration, the request will replace the existing configuration.
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
configuration | Describes all the cross-origin configuration | QCloudBucketReplicationConfiguration* | Yes |
To use this API, version management must be enabled for the bucket. For more information on version management, see Put Bucket Versioning.
QCloudPutBucketReplicationRequest* request = [[QCloudPutBucketReplicationRequest alloc] init];
request.bucket = @"source-bucket";
QCloudBucketReplicationConfiguation* configuration = [[QCloudBucketReplicationConfiguation alloc] init];
configuration.role = [NSString identifierStringWithID:@"uin" :@"uin"];
QCloudBucketReplicationRule* rule = [[QCloudBucketReplicationRule alloc] init];
rule.identifier = @"identifier";
rule.status = QCloudQCloudCOSXMLStatusEnabled;
QCloudBucketReplicationDestination* destination = [[QCloudBucketReplicationDestination alloc] init];
//qcs:id/0:cos:[region]:appid/[AppId]:[bucketname]
NSString* destinationBucket = @"destinationBucket";
NSString* region = @"destinationRegion"
destination.bucket = [NSString stringWithFormat:@"qcs:id/0:cos:%@:appid/%@:%@",@"region",@"appid",@"destinationBucket"];
rule.destination = destination;
configuration.rule = @[rule];
request.configuation = configuration;
[request setFinishBlock:^(id outputObject, NSError* error) {
//Set the completion callback
}];
[[QCloudCOSXMLService defaultCOSXML] PutBucketRelication:request];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
This API (Get Bucket Replication) is used to read the cross-origin replication configuration information in a bucket.
Parameter Name | Description | Type |
---|---|---|
role | Initiator ID, in the format of qcs::cam::uin/ |
NSString* |
rule | Specific configuration information. Up to 1000 rules are supported. All rules must be directed to one destination bucket. | NSArray<QCloudBucketReplicationRule*> * |
Parameter Name | Description | Type |
---|---|---|
status | Indicates whether the Rule takes effect | QCloudQCloudCOSXMLStatus |
identifier | Indicates the name of a specific Rule | NSString* |
prefix | Prefix match policy (blank for root directory). Prefixes cannot overlap; otherwise, an error is returned. | NSString* |
destination | Destination bucket information | QCloudBucketReplicationDestination* |
QCloudGetBucketReplicationRequest* request = [[QCloudGetBucketReplicationRequest alloc] init];
request.bucket = @"testBucket-123456789";
[request setFinishBlock:^(QCloudBucketReplicationConfiguation* result, NSError* error) {
//Set the completion callback
}];
[[QCloudCOSXMLService defaultCOSXML] GetBucketReplication:request];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
This API (Delete Bucket Replication) is used to delete the cross-origin replication configuration in a bucket.
QCloudDeleteBucketReplicationRequest* request = [[QCloudDeleteBucketReplicationRequest alloc] init];
request.bucket = @"testBucket-123456789";
[request setFinishBlock:^(id outputObject, NSError* error) {
//Set the completion callback
}];
[[QCloudCOSXMLService defaultCOSXML] DeleteBucketReplication:request];
In COS, each file is an Object. Operating on a file is actually operating on an Object.
Simple upload only applies to files less than 20 MB, and supports uploading files from memory.
The number of access policies is up to 1000. Do not set object ACL control when you upload an object if it is not required. The object inherits the bucket permissions by default.
Parameter Name | Description | Type | Required |
---|---|---|---|
Object | ObjectKey is the unique identifier of an object in a bucket. For example, in the object's access domain name "bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg", the ObjectKey is "doc1/pic1.jpg". For more information, see Object Description. | NSString * | Yes |
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
body | If a file is stored in the disk, it is the path of the file to be uploaded, and you can enter a variable of NSURL * type. If a file is stored in memory, you can enter a variable of NSData * type that contains the file binary data. | BodyType | Yes |
storageClass | Storage class of an object | QCloudCOSStorageClass | Yes |
cacheControl | Cache policy defined in RFC 2616 | NSString * | No |
contentDisposition | File name defined in RFC 2616 | NSString * | No |
expect | When expect=@"100-Continue" is used, the request content will not be sent until the receipt of response from server. | NSString * | No |
expires | Expiration time defined in RFC 2616 | NSString * | No |
initMultipleUploadFinishBlock | If the request generates a multipart upload request, after the initialization of multipart upload, a callback is performed via the block. The bucket, key, and uploadID after the completion of multipart upload, and ResumeData for resuming subsequent failed upload can be obtained from this callback block. | block | No |
accessControlList | Defines the ACL attribute of an object. Valid values: private, public-read-write, public-read; Default: private | NSString * | No |
grantRead | Grants read permission to the authorized user. Format: id=" ",id=" ". For authorization to a subaccount, id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>"; for authorization to the root account, id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>", where OwnerUin refers to the ID of the root account and SubUin refers to the ID of the subaccount. | NSString * | No |
grantWrite | Grants write permission to the authorized user. The format is the same as above. | NSString * | No |
grantFullControl | Grants read and write permissions to the authorized user. The format is the same as above. | NSString * | No |
QCloudPutObjectRequest* put = [QCloudPutObjectRequest new];
put.object = @"object-name";
put.bucket = @"bucket-12345678";
put.body = [@"testFileContent" dataUsingEncoding:NSUTF8StringEncoding];
[put setFinishBlock:^(id outputObject, NSError *error) {
//Complete callback
if (nil == error) {
//Successful
}
}];
[[QCloudCOSXMLService defaultCOSXML] PutObject:put];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before file operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudGetObjectACLRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
object | ObjectKey is the unique identifier of an object in a bucket. For example, in the object's access domain name "bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg", the key is "doc1/pic1.jpg". For more information, see Object Description. | NSString * | Yes |
request.bucket = self.aclBucket;
request.object = @"Object name";
request.bucket = @"testBucket-123456789"
__block QCloudACLPolicy* policy;
[request setFinishBlock:^(QCloudACLPolicy * _Nonnull result, NSError * _Nonnull error) {
policy = result;
}];
[[QCloudCOSXMLService defaultCOSXML] GetObjectACL:request];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The number of access policies is up to 1000. Do not set object ACL control if it is not required. The object inherits the bucket permissions by default.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before object operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudPutObjectACLRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
object | Object name | NSString * | Yes |
accessControlList | Defines the ACL attribute of an object. Valid values: private, public-read-write, public-read; Default: private | NSString * | No |
grantRead | Grants read permission to the authorized user. Format: id=" ",id=" ". For authorization to a subaccount, id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>", for authorization to the root account, id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>", where OwnerUin refers to the ID of the root account and SubUin refers to the ID of the subaccount |
NSString * | No |
grantWrite | Grants write permission to the authorized user. The format is the same as above. | NSString * | No |
grantFullControl | Grants read and write permissions to the authorized user. The format is the same as above. | NSString * | No |
QCloudPutObjectACLRequest* request = [QCloudPutObjectACLRequest new];
request.object = @"Name of the object whose ACL needs to be set";
request.bucket = @"testBucket-123456789";
NSString *ownerIdentifier = [NSString stringWithFormat:@"qcs::cam::uin/%@:uin/%@",self.appID, self.appID];
NSString *grantString = [NSString stringWithFormat:@"id=\"%@\"",ownerIdentifier];
request.grantFullControl = grantString;
__block NSError* localError;
[request setFinishBlock:^(id outputObject, NSError *error) {
localError = error;
}];
[[QCloudCOSXMLService defaultCOSXML] PutObjectACL:request];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before file operations. Before that, you need to complete the initialization described in Getting Started by creating an instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
object | Object name | NSString * | Yes |
range | The specified range of file download defined in RFC 2616 (in bytes) | NSString * | No |
ifModifiedSince | The file content is only returned if the file is modified after the specified time. Otherwise, 412 (not modified) is returned. | NSString * | No |
responseContentType | Sets the Content-Type parameter in the response header | NSString * | No |
responseContentLanguage | Sets the Content-Language parameter in the response header | NSString * | No |
responseContentExpires | Sets the Content-Expires parameter in the response header | NSString * | No |
responseCacheControl | Sets the Cache-Control parameter in the response header | NSString * | No |
responseContentDisposition | Sets the Content-Disposition parameter in the response header | NSString * | No |
responseContentEncoding | Sets the Content-Encoding parameter in the response header | NSString * | No |
QCloudGetObjectRequest* request = [QCloudGetObjectRequest new];
//Set the URL for download. If it has been set, the file is downloaded to the specified path. Otherwise, the file is downloaded to outputObject of finishBlock in memory.
request.downloadingURL = [NSURL URLWithString:QCloudTempFilePathWithExtension(@"downding")];
request.object = @“Your Object-Key”;
request.bucket = @"testBucket-123456789";
[request setFinishBlock:^(id outputObject, NSError *error) {
//additional actions after finishing
}];
[request setDownProcessBlock:^(int64_t bytesDownload, int64_t totalBytesDownload, int64_t totalBytesExpectedToDownload) {
//Progress of download
}];
[[QCloudCOSXMLService defaultCOSXML] GetObject:request];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before file operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudOptionsObjectRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
object | ObjectKey is the unique identifier of an object in a bucket. For example, in the object's access domain name "bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg", the key is "doc1/pic1.jpg". For more information, see Object Description. | NSString * | Yes |
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
accessControlRequestMethod | The HTTP method of the simulate CORS request | NSArray<NSString* > * |
Yes |
origin | The access sources allowed for the simulate CORS. The wildcard "*" is supported. Format: protocol://domain name[:port], for example, http://www.qq.com . |
NSString * | Yes |
allowedHeader | It is used to notify the server about which custom HTTP request headers are allowed for subsequent requests when an OPTIONS request is sent. The wildcard "*" is supported. | NSArray<NSString * > * |
No |
QCloudOptionsObjectRequest* request = [[QCloudOptionsObjectRequest alloc] init];
request.bucket =@"Bucket name";
request.origin = @"*";
request.accessControlRequestMethod = @"get";
request.accessControlRequestHeaders = @"host";
request.object = @"Object name";
__block id resultError;
[request setFinishBlock:^(id outputObject, NSError* error) {
resultError = error;
}];
[[QCloudCOSXMLService defaultCOSXML] OptionsObject:request];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before file operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudDeleteObjectRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Type | Required | Description |
---|---|---|---|
object | ObjectKey is the unique identifier of an object in a bucket. For example, in the object's access domain name "bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg", the key is "doc1/pic1.jpg". For more information, see Object Description. | NSString * | Yes |
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
QCloudDeleteObjectRequest* deleteObjectRequest = [QCloudDeleteObjectRequest new];
deleteObjectRequest.bucket = @"testBucket-123456789";
deleteObjectRequest.object = @"Object name";
__block NSError* resultError;
[deleteObjectRequest setFinishBlock:^(id outputObject, NSError *error) {
resultError = error;
}];
[[QCloudCOSXMLService defaultCOSXML] DeleteObject:deleteObjectRequest];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before file operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudDeleteMultipleObjectRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
object | ObjectKey is the unique identifier of an object in a bucket. For example, in the object's access domain name "bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg", the key is "doc1/pic1.jpg". For more information, see Object Description. | NSString * | Yes |
deleteObjects | Encapsulates information of multiple objects to be deleted in batches | QCloudDeleteInfo * | Yes |
Parameter Name | Description | Type | Required |
---|---|---|---|
objects | An array containing information on the objects to be deleted | NSArray<QCloudDeleteObjectInfo * > * |
Yes |
Parameter Name | Description | Type | Required |
---|---|---|---|
key | ObjectKey is the unique identifier of an object in a bucket. For example, in the object's access domain name "bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg", the key is "doc1/pic1.jpg". For more information, see Object Description. | NSString * | Yes |
QCloudDeleteMultipleObjectRequest* delteRequest = [QCloudDeleteMultipleObjectRequest new];
delteRequest.bucket = @"testBucket-123456789";
QCloudDeleteObjectInfo* deletedObject0 = [QCloudDeleteObjectInfo new];
deletedObject0.key = @"Name of the first object";
QCloudDeleteObjectInfo* deleteObject1 = [QCloudDeleteObjectInfo new];
deleteObject1.key = @"Name of the second object";
QCloudDeleteInfo* deleteInfo = [QCloudDeleteInfo new];
deleteInfo.quiet = NO;
deleteInfo.objects = @[ deletedObject0,deleteObject2];
delteRequest.deleteObjects = deleteInfo;
__block NSError* resultError;
[delteRequest setFinishBlock:^(QCloudDeleteResult* outputObject, NSError *error) {
localError = error;
deleteResult = outputObject;
}];
[[QCloudCOSXMLService defaultCOSXML] DeleteMultipleObject:delteRequest];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before file operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudInitiateMultipartUploadRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
Object | The name of the file (object) to be uploaded, i.e. the key of the object. ObjectKey is the unique identifier of an object in a bucket. For example, in the object's access domain name "bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg", the key is "doc1/pic1.jpg". For more information, see Object Description. | NSString * | Yes |
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
cacheControl | Cache policy defined in RFC 2616 | NSString * | No |
contentDisposition | File name defined in RFC 2616 | NSString * | No |
expect | When expect=@"100-continue" is used, the request content will not be sent until the receipt of response from server. |
NSString * | No |
expires | Expiration time defined in RFC 2616 | NSString * | No |
storageClass | Storage class of an object | QCloudCOSStorageClass | No |
accessControlList | Defines the ACL attribute of an object. Valid values: private, public-read-write, public-read; Default: private | NSString * | No |
grantRead | Grants read permission to the authorized user. Format: id=" ",id=" ". For authorization to a subaccount, id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>", for authorization to the root account, id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>", where OwnerUin refers to the ID of the root account and SubUin refers to the ID of the subaccount |
NSString * | No |
grantWrite | Grants write permission to the authorized user. The format is the same as above. | NSString * | No |
grantFullControl | Grants read and write permissions to the authorized user. The format is the same as above. | NSString * | No |
QCloudInitiateMultipartUploadRequest* initrequest = [QCloudInitiateMultipartUploadRequest new];
initrequest.bucket = @"testBucket-123456789";
initrequest.object = @"Object name";
__block QCloudInitiateMultipartUploadResult* initResult;
[initrequest setFinishBlock:^(QCloudInitiateMultipartUploadResult* outputObject, NSError *error) {
initResult = outputObject;
}];
[[QCloudCOSXMLService defaultCOSXML] InitiateMultipartUpload:initrequest];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
The header file QCloudCOSXML/QCloudCOSXML.h needs to be imported before file operations. Before that, you need to complete the initialization described in Getting Started by creating a QCloudHeadObjectRequest instance and enter some additional restrictions as needed to get the approved content. Specific steps are as follows:
Parameter Name | Description | Type | Required |
---|---|---|---|
Object | ObjectKey is the unique identifier of an object in a bucket. For example, in the object's access domain name "bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg", the key is "doc1/pic1.jpg". For more information, see Object Description. | NSString * | Yes |
bucket | Bucket name, which can be found in the COS V5 Console, with a format of <bucketName>-<APPID>, such as testBucket-1253653367. | NSString * | Yes |
ifModifiedSince | The file content is only returned if the file is modified after the specified time. Otherwise, 304 (not modified) is returned. | NSString * | Yes |
QCloudHeadObjectRequest* headerRequest = [QCloudHeadObjectRequest new];
headerRequest.object = @“Object name”;
headerRequest.bucket = @"testBucket-123456789";
__block id resultError;
[headerRequest setFinishBlock:^(NSDictionary* result, NSError *error) {
resultError = error;
}];
[[QCloudCOSXMLService defaultCOSXML] HeadObject:headerRequest];
When the SDK request fails, the error returned is not empty and includes the error code, error description, and other necessary debugging information to help developers quickly solve the problem.
Error codes (encapsulated in the returned error) include those returned by the device due to network problems and those returned by COS.
You can add custom headers as needed. Classes allowing addition of custom headers are provided with the attribute customHeaders:
@property (strong, nonatomic) NSMutableDictionary* customHeaders;
Key-value pairs in this attribute will be added to the HTTP headers of creation requests accordingly.
You can encrypt the uploaded objects in the following ways.
COS can automatically encrypt data as it is written to the IDC and automatically decrypt it when you access it. COS master key is used to apply AES-256 encryption to data.
You can achieve this by calling -(void)setCOSServerSideEncyption in the iOS SDK.
[request setCOSServerSideEncyption];
You can achieve this by calling -(void)setCOSServerSideEncyptionWithCustomerKey:(NSString *)customerKey in the iOS SDK.
Note:
NSString *customKey = @"123456qwertyuioplkjhgfdsazxcvbnm";
[put setCOSServerSideEncyptionWithCustomerKey:customKey];
The iOS SDK supports HTTPS requests. You only need to, when initializing the configuration object QCloudServiceConfiguration, set useHTTPS for its endpoint to YES.
QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];
configuration.appID = kAppID;
configuration.signatureProvider = self;
QCloudCOSXMLEndPoint* endpoint = [[QCloudCOSXMLEndPoint alloc] init];
endpoint.regionName = kRegion;
endpoint.useHTTPS = YES;
configuration.endpoint = endpoint;
[QCloudCOSXMLService registerDefaultCOSXMLWithConfiguration:configuration];
[QCloudCOSTransferMangerService registerDefaultCOSTransferMangerWithConfiguration:configuration];
}
Was this page helpful?