Inventory

Last updated: 2020-03-20 09:27:11

PDF

Note

This document provides an overview of inventory's API and SDK sample code.

API Operation name pedagogical operation
PUT Bucket inventory Set up inventory job Inventory and job who set up Bucket
GET Bucket inventory Inquire about inventory job Inquire about inventory and job of Bucket
DELETE Bucket inventory Delete inventory job Delete inventory and job of Bucket

Set up inventory job

Function description

PUT Bucket inventory is used to create inventory and job in Bucket.

Method prototype

When you start using COS, you need to create a Bucket under the specified account to facilitate the use and management of objects, and specify the region to which Bucket belongs. The user who created Bucket becomes the holder of Bucket by default. If Access and Permission are not specified when Bucket is created, it defaults to Permission, a private read-write (private). The specific steps are as follows:

  1. Instantiate QCloudPutBucketInventoryRequest
  2. Call the PutBucketInventory method in the QCloudCOSXMLService object to make the request.
  3. Get the specific content from the outputObject in the finishBlock of the callback.

Request Sample

QCloudPutBucketInventoryRequest *putReq = [QCloudPutBucketInventoryRequest new];
   putReq.bucket= @"examplebucket-1250000000";
   putReq.inventoryID = @"list1";
   QCloudInventoryConfiguration *config = [QCloudInventoryConfiguration new];
   config.identifier = @"list1";
   config.isEnabled = @"True";
   QCloudInventoryDestination *des = [QCloudInventoryDestination new];
   QCloudInventoryBucketDestination *btDes =[QCloudInventoryBucketDestination new];
   btDes.cs = @"CSV";
   btDes.account = @"1278687956";
   btDes.bucket  = @"qcs::cos:ap-guangzhou::examplebucket-1250000000";
   btDes.prefix = @"list1";
   QCloudInventoryEncryption *enc = [QCloudInventoryEncryption new];
   enc.ssecos = @"";
   btDes.encryption = enc;
   des.bucketDestination = btDes;
   config.destination = des;
   QCloudInventorySchedule *sc = [QCloudInventorySchedule new];
   sc.frequency = @"Daily";
   config.schedule = sc;
   QCloudInventoryFilter *fileter = [QCloudInventoryFilter new];
   fileter.prefix = @"myPrefix";
   config.filter = fileter;
   config.includedObjectVersions = QCloudCOSIncludedObjectVersionsAll;
   QCloudInventoryOptionalFields *fields = [QCloudInventoryOptionalFields new];
   fields.field = @[ @"Size",@"LastModifiedDate",@"ETag",@"StorageClass",@"IsMultipartUploaded",@"ReplicationStatus"];
   config.optionalFields = fields;
   putReq.inventoryConfiguration = config;
   [putReq setFinishBlock:^(id outputObject, NSError *error) {


   }];
   [[QCloudCOSXMLService defaultCOSXML] PutBucketInventory:putReq];

Swift code example:

let putReq = QCloudPutBucketInventoryRequest.init();
putReq.bucket = "examplebucket-1250000000";
putReq.inventoryID = "list1";
let config = QCloudInventoryConfiguration.init();
config.identifier = "list1";
config.isEnabled = "True";
let des = QCloudInventoryDestination.init();
let btDes = QCloudInventoryBucketDestination.init();
btDes.cs = "CSV";
btDes.account = "1278687956";
btDes.bucket  = "qcs::cos:ap-guangzhou::examplebucket-1250000000";
btDes.prefix = "list1";
let enc = QCloudInventoryEncryption.init();
enc.ssecos = "";
btDes.encryption = enc;
des.bucketDestination = btDes;
config.destination = des;
let sc = QCloudInventorySchedule.init();
sc.frequency = "Daily";
config.schedule = sc;
let fileter = QCloudInventoryFilter.init();
fileter.prefix = "myPrefix";
config.filter = fileter;
config.includedObjectVersions = .all;
let fields = QCloudInventoryOptionalFields.init();
fields.field = [ "Size","LastModifiedDate","ETag","StorageClass","IsMultipartUploaded","ReplicationStatus"];
config.optionalFields = fields;
putReq.inventoryConfiguration = config;

putReq.finishBlock = {(result,error) in

    if error != nil{
        print(error!);
    }else{
        print( result!);
    }
}

QCloudCOSXMLService.defaultCOSXML().putBucketInventory(putReq);

Parameter description

QCloudPutBucketInventoryRequest request parameter description

Parameter name Description Type Required/Optional
Bucket Set the format of Bucket of inventory and job to BucketName-APPID. For more information, please see Naming convention NSString * Yes
InventoryID The name of inventory job. Default value: None; Valid character: a muri zMAE AlyzMagol 0Rue 9MAE, _ ,. NSString * Yes
InventoryConfiguration Describe the status of the logging configuration QCloudInventoryConfiguration * Yes

QCloudInventoryConfiguration parameter description

Parameter name Description Type Required/Optional
Identifier The name of inventory, which corresponds to the ID in the request parameters NSString * Yes
IsEnabled The logo of whether inventory is enabled:
  • If set to True, inventory function will take effect.
  • If set to False, no inventory will be generated.
  • NSString * Yes
    IncludedObjectVersions Whether to include the object version in inventory:
  • If set to All, all object versions will be included in inventory, and the fields VersionId,IsLatest,DeleteMarker will be added to inventory.
  • If set to Current, inventory does not contain object version information.
  • QCloudCOSIncludedObjectVersions * Yes
    Destination Describe the information that stores inventory's results QCloudInventoryDestination * Yes
    Schedule Filter the objects to be analyzed. Inventory function will analyze objects that conform to the prefix set in Filter QCloudInventorySchedule * Yes
    Filter Describe the information that stores inventory's results QCloudInventoryFilter * No
    OptionalFields The name of the analysis project that can be included in inventory's result. Optional fields include: Size,LastModifiedDate,StorageClass,ETag,IsMultipartUploaded,ReplicationStatus QCloudInventoryOptionalFields * No

    Returns the error code description

    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.

    • For Device's own error codes due to network reasons, they are all negative and four digits, for example,-1001. This kind of error code is defined by Apple. For more information, please see the definition in the NSURLError.h header file in the Foundation framework, or Apple official documentation Description.
    • The error code returned by COS is based on the status code of HTTP, that is, 404503. For such error codes, see API Error Codes The document seeks a solution.
    • For the error codes customized by SDK, they are all 5 digits and all are positive numbers, such as 10000, 20000, and so on. For such error codes, see SDK Error Codes The document seeks a solution.

    Error code description

    Some common special errors that may occur in this request are as follows:

    Error Codes Description Status Code
    InvalidArgument Invalid's parameter value HTTP 400 Bad Request
    TooManyConfigurations The number of inventory has reached the upper limit of 1000. HTTP 400 Bad Request
    AccessDenied Unauthorized Access. You may not have Permission of Access and Bucket. HTTP 403 Forbidden

    Inquire about inventory job

    Function description

    GET Bucket inventory is used to query inventory and job information of users in Bucket.

    Method prototype

    When you start using COS, you need to create a Bucket under the specified account to facilitate the use and management of objects, and specify the region to which Bucket belongs. The user who created Bucket becomes the holder of Bucket by default. If Access and Permission are not specified when Bucket is created, it defaults to Permission, a private read-write (private). The specific steps are as follows:

    1. Instantiate QCloudGetBucketInventoryRequest
    2. Call the GetBucketInventory method in the QCloudCOSXMLService object to make the request.
    3. Get the specific content from the result in the finishBlock of the callback.

    Request Sample

    QCloudGetBucketInventoryRequest *getReq = [QCloudGetBucketInventoryRequest new];
    getReq.bucket = @"examplebucket-1250000000";
    getReq.inventoryID = @"list1";
    [getReq setFinishBlock:^(QCloudInventoryConfiguration * _Nonnull result, NSError * _Nonnull error) {
    
    }];
    [[QCloudCOSXMLService defaultCOSXML] GetBucketInventory:getReq];
    

    Swift code example:

    let req = QCloudGetBucketInventoryRequest.init();
    req.bucket = "examplebucket-1250000000";
    req.inventoryID = "list1";
    req.setFinish {(result,error) in
    
        if error != nil{
            print(error!);
        }else{
            print( result!);
        }
    }
    QCloudCOSXMLService.defaultCOSXML().getBucketInventory(req);
    

    Parameter description

    QCloudGetBucketInventoryRequest request parameter description

    Parameter name Description Type Required/Optional
    Bucket Query inventory job's Bucket in BucketName-APPID format. For more information, please see Naming convention NSString * Yes
    InventoryID The name of inventory job. Default value: None; Valid character: a muri zMAE AlyzMagol 0Rue 9MAE, _ ,. NSString * Yes

    Return result description

    QCloudInventoryConfiguration parameter description

    Parameter name Description Type
    Identifier The name of inventory, which corresponds to the ID in the request parameters NSString *
    IsEnabled The logo of whether inventory is enabled:
  • If set to True, inventory function will take effect.
  • If set to False, no inventory will be generated.
  • NSString *
    IncludedObjectVersions Whether to include the object version in inventory:
  • If set to All, all object versions will be included in inventory, and the fields VersionId,IsLatest,DeleteMarker will be added to inventory.
  • If set to Current, inventory does not contain object version information.
  • QCloudCOSIncludedObjectVersions *
    Destination Describe the information that stores inventory's results QCloudInventoryDestination *
    Schedule Filter the objects to be analyzed. Inventory function will analyze objects that conform to the prefix set in Filter QCloudInventorySchedule *
    Filter Describe the information that stores inventory's results QCloudInventoryFilter *
    OptionalFields The name of the analysis project that can be included in inventory's result. Optional fields include: Size,LastModifiedDate,StorageClass,ETag,IsMultipartUploaded,ReplicationStatus QCloudInventoryOptionalFields *

    Returns the error code description

    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.

    • For Device's own error codes due to network reasons, they are all negative and four digits, for example,-1001. This kind of error code is defined by Apple. For more information, please see the definition in the NSURLError.h header file in the Foundation framework, or Apple official documentation Description.
    • The error code returned by COS is based on the status code of HTTP, that is, 404503. For such error codes, see API Error Codes The document seeks a solution.
    • For the error codes customized by SDK, they are all 5 digits and all are positive numbers, such as 10000, 20000, and so on. For such error codes, see SDK Error Codes The document seeks a solution.

    Delete inventory job

    Function description

    DELETE Bucket inventory is used to delete inventory and job specified in Bucket.

    Method prototype

    When you start using COS, you need to create a Bucket under the specified account to facilitate the use and management of objects, and specify the region to which Bucket belongs. The user who created Bucket becomes the holder of Bucket by default. If Access and Permission are not specified when Bucket is created, it defaults to Permission, a private read-write (private). The specific steps are as follows:

    1. Instantiate QCloudDeleteBucketInventoryRequest
    2. Call the DeleteBucketInventory method in the QCloudCOSXMLService object to make the request.
    3. Get the specific content from the outputObject in the finishBlock of the callback.

    Request Sample

    QCloudDeleteBucketInventoryRequest *delReq = [QCloudDeleteBucketInventoryRequest new];
    delReq.bucket = @"examplebucket-1250000000";
    delReq.inventoryID = @"list1";
    [delReq setFinishBlock:^(id outputObject, NSError *error) {
    
    }];
    [[QCloudCOSXMLService defaultCOSXML] DeleteBucketInventory:delReq];
    

    Swift code example:

    let delReq = QCloudDeleteBucketInventoryRequest.init();
    delReq.bucket = "examplebucket-1250000000";
    delReq.inventoryID = "list1";
    delReq.finishBlock = {(result,error) in
    
        if error != nil{
            print(error!);
        }else{
            print( result!);
        }
    }
    
    QCloudCOSXMLService.defaultCOSXML().deleteBucketInventory(delReq);
    

    Parameter description

    QCloudDeleteBucketInventoryRequest request parameter description

    Parameter name Description Type Required/Optional
    Bucket Bucket of inventory job is deleted in BucketName-APPID format. For more information, please see Naming convention NSString * Yes
    InventoryID The name of inventory job. Default value: None; Valid character: a muri zMAE AlyzMagol 0Rue 9MAE, _ ,. NSString * Yes

    Returns the error code description

    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.

    • For Device's own error codes due to network reasons, they are all negative and four digits, for example,-1001. This kind of error code is defined by Apple. For more information, please see the definition in the NSURLError.h header file in the Foundation framework, or Apple official documentation Description.
    • The error code returned by COS is based on the status code of HTTP, that is, 404503. For such error codes, see API Error Codes The document seeks a solution.
    • For the error codes customized by SDK, they are all 5 digits and all are positive numbers, such as 10000, 20000, and so on. For such error codes, see SDK Error Codes The document seeks a solution.