### Create a Bucket with All Parameters Source: https://cloud.tencent.com/document/product/436/35150 This example demonstrates creating a bucket using all available parameters, including advanced configurations like BucketAZConfig, ACL, and specific grants. Use this for fine-grained control over bucket properties. ```python response = client.create_bucket( Bucket='examplebucket-1250000000', BucketAZConfig='string', ACL='private'|'public-read'|'public-read-write', GrantFullControl='string', GrantRead='string', GrantWrite='string' ) ``` -------------------------------- ### Initialize COSClient for Quick Start Source: https://cloud.tencent.com/document/product/436/6530 This example shows initializing the COSClient using configuration settings for the quick start guide. ```objective-c COSClient *client= [[COSClient alloc] initWithAppId:appId withRegion:[Congfig instance].region]; ``` -------------------------------- ### GetBucket Request Example Source: https://cloud.tencent.com/document/product/436/109473 This snippet shows how to initiate a GetBucket request, set parameters like prefix and max keys, and process the response, including iterating through the returned objects and checking for truncation. ```cpp void GetBucketDemo(qcloud_cos::CosAPI& cos) { qcloud_cos::GetBucketReq req(bucket_name); // 设置列出的对象名以 prefix 为前缀 req.SetPrefix("test"); // 设置最大列出多少个对象, 一次 listobject 最大支持1000 req.SetMaxKeys(10); qcloud_cos::GetBucketResp resp; qcloud_cos::CosResult result = cos.GetBucket(req, &resp); std::cout << "===================GetBucketResponse=====================" << std::endl; if (result.IsSucc()) { // object contents 表示此次列出的对象列表 std::vector contents = resp.GetContents(); for (const Content& content : contents) { // 对象的 key std::string key = content.m_key; // 对象的 etag std::string etag = content.m_etag; // 对象的长度 std::string file_size = content.m_size; // 对象的存储类型 std::string storage_classes = content.m_storage_class; std::cout << "key:" << key << "\netag:" << etag << "\nfile_size:" << file_size << "\nstorage_classes:" << storage_classes << std::endl; std::cout << "==================================" << std::endl; }  if (resp.IsTruncated()) { // 表示还没有列完,被截断了 // 下一次开始的位置 std::string next_marker = resp.GetNextMarker(); std::cout << "next_marker:" << next_marker << std::endl; } } else { std::cout << "GetBucket Fail, ErrorMsg: " << result.GetErrorMsg() << std::endl; } std::cout << "=========================================================" << std::endl; } ``` -------------------------------- ### JavaScript SDK Installation and Usage Source: https://cloud.tencent.com/document/product/436/55928 This snippet provides a link to the quick start guide for installing and using the JavaScript SDK. It is useful for developers integrating COS with web applications. ```javascript 详情请参见 JavaScript SDK 快速入门。 ``` -------------------------------- ### Create Directory Example Source: https://cloud.tencent.com/document/product/436/6272 Example of creating a directory in a specified bucket. The 'bizAttr' parameter is for folder attributes. ```cpp FolderCreateReq folderCreateReq(bucket,folder,folder_biz_attr); string rsp = cos.FolderCreate(folderCreateReq); ``` -------------------------------- ### Get Document Page Number Example Source: https://cloud.tencent.com/document/product/436/104962 This example demonstrates how to retrieve the total number of pages for a document using the document processing feature. Refer to the detailed guide for specific implementation. ```plaintext https://example-1250000000.cos.ap-beijing.myqcloud.com/filename.pptx?ci-process=doc-preview&page=3&srcTypr=pptx ``` -------------------------------- ### Synchronous File Hash Calculation Request Example Source: https://cloud.tencent.com/document/product/436/83107 This example demonstrates how to make a GET request to calculate the MD5 hash of a file synchronously. Ensure you have the correct authorization and COS bucket setup. ```HTTP GET /for-test.mp4?ci-process=filehash&type=md5 HTTP/1.1 Host: test-1234567890.cos.ap-beijing.myqcloud.com Authorization: q-sign-algorithm=sha1&q-ak=************************************027&q-key-time=1484213027;32557109027&q-header-list=host&q-url-param-list=acl&q-signature=**************************************** Content-Length: 0 ``` -------------------------------- ### Object Storage API Quick Start Source: https://cloud.tencent.com/document/product/436/85069 Guides users through the initial steps required to use the Tencent Cloud Object Storage API, including enabling the service, creating a bucket, obtaining API credentials, and implementing request signing. ```APIDOC ## Quick Start To use the Tencent Cloud Object Storage API, you need to perform the following steps first: 1. Enable Tencent Cloud Object Storage (COS) service in the Tencent Cloud Object Storage Console. 2. Create a Bucket in the Tencent Cloud Object Storage Console. 3. Obtain your APPID, and create SecretId and SecretKey from the API Key Management page in the Access Management console. 4. Write a request signature algorithm program (or use any server-side SDK). For details, see the Request Signature document. 5. Calculate the signature and call the API to perform operations. ``` -------------------------------- ### Object Storage API Quick Start Source: https://cloud.tencent.com/document/product/436/7751 Guides users through the initial steps required to use the Tencent Cloud Object Storage API, including service activation, bucket creation, and obtaining API credentials. ```APIDOC ## Quick Start To use the Tencent Cloud Object Storage API, follow these steps: 1. Activate Tencent Cloud Object Storage (COS) service in the [Tencent Cloud Object Storage Console](link_to_cos_console). 2. Create a Bucket in the [Tencent Cloud Object Storage Console](link_to_cos_console). 3. Obtain your APPID, and create SecretId and SecretKey from the [API Key Management](link_to_api_key_management) page in the Access Management console. 4. Write a request signature algorithm program (or use any server-side SDK). For details, refer to the [Request Signature](link_to_request_signature) document. 5. Calculate the signature and call the API to perform operations. ``` -------------------------------- ### GetObjectAcl PHP SDK Example Source: https://cloud.tencent.com/document/product/436/41898 This snippet demonstrates how to use the Qcloud COS SDK for PHP to get the ACL of an object. It shows the necessary setup, the function call, and how to handle the response or potential errors. ```APIDOC ## GetObjectAcl ### Description Retrieves the Access Control List (ACL) of an object. ### Method POST (Implicitly via SDK method) ### Endpoint Not directly exposed via HTTP in this SDK example, but the SDK method `getObjectAcl` is used. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Parameters are passed as an array to the SDK method) ### SDK Method Parameters - **Bucket** (string) - Required - The name of the storage bucket, formatted as BucketName-Appid. - **Key** (string) - Required - The key (name) of the object. ### Request Example ```php $region, 'scheme' => 'https', 'credentials'=> array( 'secretId' => $secretId , 'secretKey' => $secretKey))) ); try { $result = $cosClient->getObjectAcl(array( 'Bucket' => 'examplebucket-1250000000', 'Key' => 'exampleobject', )); // Request successful print_r($result); } catch ( Exception $e) { // Request failed echo($e); } ``` ### Response #### Success Response (200) - **data** (Array) - Contains the ACL details. - **Owner** (Array) - Information about the object owner. - **ID** (String) - The unique identifier of the owner. - **DisplayName** (String) - The display name of the owner. - **Grants** (Array) - A list of ACL grants. - **Grant** (Array) - Details of a single grant. - **Grantee** (Array) - Information about the grantee. - **ID** (String) - The unique identifier of the grantee. - **DisplayName** (String) - The display name of the grantee. - **Permission** (String) - The type of permission granted (e.g., FULL_CONTROL, WRITE, READ). - **RequestId** (String) - The ID of the request. #### Response Example ```json { "data": { "Owner": { "ID": "qcs::cam::uin/100000000001:uin/100000000001", "DisplayName": "qcs::cam::uin/100000000001:uin/100000000001" }, "Grants": [ { "Grantee": { "ID": "qcs::cam::uin/100000000001:uin/100000000001", "DisplayName": "qcs::cam::uin/100000000001:uin/100000000001" }, "Permission": "FULL_CONTROL" } ], "RequestId": "NWE3YzhjMTRfYzdhMzNiMGFfYjdiOF8yYzZmMzU=" } } ``` ``` -------------------------------- ### GET Request Example with Parameters Source: https://cloud.tencent.com/document/product/436/120622 An example of a GET request to the jobs endpoint, including authentication headers and query parameters. ```http GET /jobs?queueId=p2242ab62c7c94486915508540933a2c6&tag=Transcode HTTP/1.1 Authorization: q-sign-algorithm=sha1&q-ak=************************************&q-sign-time=1497530202;1497610202&q-key-time=1497530202;1497610202&q-header-list=&q-url-param-list=&q-signature=**************************************** Host: test-1234567890.ci.ap-chongqing.myqcloud.com ``` -------------------------------- ### OPTIONS /exampleobject Source: https://cloud.tencent.com/document/product/436/8288 This example demonstrates a preflight OPTIONS request to check if a GET request is allowed on an object. ```APIDOC ## OPTIONS /exampleobject ### Description This endpoint is used to make a preflight OPTIONS request to check if a GET request is allowed on an object. It includes headers like `Host`, `Date`, `Origin`, `Access-Control-Request-Method`, and `Access-Control-Request-Headers`. ### Method OPTIONS ### Endpoint `/exampleobject` ### Request Example ```http OPTIONS /exampleobject HTTP/1.1 Host: examplebucket-1250000000.cos.ap-beijing.myqcloud.com Date: Thu, 09 Jul 2020 14:49:22 GMT Origin: https://example.com Access-Control-Request-Method: GET Access-Control-Request-Headers: range Connection: close ``` ### Response Example #### Success Response (200) ```http HTTP/1.1 200 OK Content-Length: 0 Connection: close Access-Control-Allow-Headers: range,x-cos-server-side-encryption-customer-algorithm,x-cos-server-side-encryption-customer-key,x-cos-server-side-encryption-customer-key-md5 Access-Control-Allow-Methods: GET,HEAD Access-Control-Allow-Origin: * Access-Control-Expose-Headers: Content-Length,ETag,x-cos-meta-author Access-Control-Max-Age: 600 Date: Thu, 09 Jul 2020 14:49:22 GMT Server: tencent-cos x-cos-request-id: NWYwNzJlNzJfZDUyNzVkNjRfYTA2Ml8yNGEz**** ``` ``` -------------------------------- ### Create Directory Source: https://cloud.tencent.com/document/product/436/46381 Example demonstrating how to create a directory within object storage. ```Python from qcloud_cos import CosConfig from qcloud_cos import CosS3Client # 1. Set configuration information secret_id = "YOUR_SECRET_ID" # Replace with your SecretId secret_key = "YOUR_SECRET_KEY" # Replace with your SecretKey region = "ap-guangzhou" # Replace with your region token = None # If the token is not null, it is a temporary token config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 2. Initialize the client client = CosS3Client(config) # 3. Create directory bucket = "your-bucket-name-1250000000" directory_name = "my_new_directory/" response = client.create_dir(Bucket=bucket, ObjectKey=directory_name) print(response) ``` -------------------------------- ### Synchronous Transcoding GET Request Example Source: https://cloud.tencent.com/document/product/436/120952 An example of a GET request for synchronous transcoding, demonstrating the required headers and parameters. ```HTTP GET /for-test.gif?ci-process=convert&format=mp4 HTTP/1.1 Host: examplebucket-1250000000.cos.ap-beijing.myqcloud.com Date: Fri, 10 Mar 2016 09:45:46 GMT Authorization: q-sign-algorithm=sha1&q-ak=**************************************-sign-time=1484213027;32557109027&q-key-time=1484213027;32557109027&q-header-list=host&q-url-param-list=acl&q-signature=**************************************** Content-Length: 0 ``` -------------------------------- ### Example GET Request for Queues Source: https://cloud.tencent.com/document/product/436/121106 This is an example of a GET request to retrieve queue information, specifying queue IDs and including authorization headers. ```http GET /ai_queue?queueIds=p4a17eeea29334bf499b7e20e2fbfd99d,A,B HTTP/1.1 Authorization: q-sign-algorithm=sha1&q-ak=************************************&q-sign-time=1497530202;1497610202&q-key-time=1497530202;1497610202&q-header-list=&q-url-param-list=&q-signature=**************************************** Host: test-1234567890.ci.ap-chongqing.myqcloud.com Content-Length: 0 Content-Type: application/xml ``` -------------------------------- ### List Bucket IntelligentTiering Configurations Request Example Source: https://cloud.tencent.com/document/product/436/106783 This example demonstrates how to construct a GET request to retrieve all intelligent tiering configurations for a specified bucket. Ensure the Host header includes the correct bucket name, APPID, and region. Authorization is required and detailed in the Request Signature documentation. ```HTTP GET /?intelligent-tiering HTTP/1.1 Host: .cos..myqcloud.com Date: GMT Date Authorization: Auth String ``` -------------------------------- ### Actual Request Example with Authorization Source: https://cloud.tencent.com/document/product/436/48988 This is a practical example of a GET request to query media buckets, demonstrating a fully formed Authorization header. ```HTTP GET /mediabucket HTTP/1.1 Authorization:q-sign-algorithm=sha1&q-ak=************************************&q-sign-time=1497530202;1497610202&q-key-time=1497530202;1497610202&q-header-list=&q-url-param-list=&q-signature=**************************************** Host: ci.ap-beijing.myqcloud.com Content-Length: 0 Content-Type: application/xml ``` -------------------------------- ### GET Bucket accelerate Actual Request Example Source: https://cloud.tencent.com/document/product/436/38868 A concrete example of a GET Bucket accelerate request, including Host, Authorization, and Content-Type headers. ```HTTP GET /?accelerate HTTP/1.1 Host: examplebucket-1250000000.cos.ap-chengdu.myqcloud.com Connection: keep-alive Authorization: authorization string Content-Type: text/plain ``` -------------------------------- ### Example GET Request for Listing Directory Contents Source: https://cloud.tencent.com/document/product/436/6062 A concrete example of an HTTP GET request to list directory contents, including the host and authorization header. ```http GET /files/v2/10055004/accesslog/aaa/bbb/?op=list&order=0&num=5 HTTP/1.1 Host: sh.file.myqcloud.com Authorization: F/mImHxxGlI5A7lLYnGa8aBtK6thPTEwMDU1MDA0Jms9QUtJRHpuOHd3S3VYanhpeFFBa1JCQzJEUlhCdFBkN0NybEpRJmU9MTQ3MjY0MDIwNiZ0PTE0NzI2NDAwMjYmcj03OTUxNzkyMCZmPSZiPWFjY2Vzc2xvZw== ``` -------------------------------- ### Example: Querying an Audio/Video Transcoding Job Source: https://cloud.tencent.com/document/product/436/120621 This practical example shows a GET request to query an audio/video transcoding job that is currently in progress. It includes a sample Authorization header. ```http GET /jobs/j8d121820f5e411ec926ef19d53ba9c6f HTTP/1.1 Accept: */* Authorization: q-sign-algorithm=sha1&q-ak=************************************&q-sign-time=1497530202;1497610202&q-key-time=1497530202;1497610202&q-header-list=&q-url-param-list=&q-signature=**************************************** Host: test-1234567890.ci.ap-chongqing.myqcloud.com ``` -------------------------------- ### List Bucket Inventory Configurations Request Example Source: https://cloud.tencent.com/document/product/436/33706 This example demonstrates how to make a GET request to list all inventory tasks for a bucket. Ensure the Host header includes your bucket name, APPID, and region. The Authorization header is required for authentication. ```HTTP GET /?inventory HTTP/1.1 Host: .cos..myqcloud.com Date: GMT Date Authorization: Auth String ``` -------------------------------- ### Install Dependencies Source: https://cloud.tencent.com/document/product/436/103844 Install the necessary Node.js packages for your server-side setup. ```bash npm install ``` -------------------------------- ### Go SDK for Object Storage - Quick Start Source: https://cloud.tencent.com/document/product/436/127754 This snippet provides a quick start guide for using the Go SDK with Tencent Cloud Object Storage, covering basic bucket operations. ```go package main import ( "fmt" "github.com/tencentyun/cos-go-sdk-v5" ) func main() { // 1. Initialize the COS client // Replace with your actual bucket name, region, and secret key bucket := "your-bucket-name-1250000000" region := "ap-guangzhou" secretID := "YOUR_SECRET_ID" secretKey := "YOUR_SECRET_KEY" // Construct the COS client u, _ := url.Parse(fmt.Sprintf("https://%s.cos.%s.myqcloud.com", bucket, region)) credential := credentials.NewStaticCredentials(secretID, secretKey, "") cosClient, _ := cos.NewClient(u, &http.Client{Transport: &cos.AuthorizationTransport{Credentials: credential}}) // 2. Bucket operations // Create a bucket (example, actual creation might require more parameters or specific permissions) // err := cosClient.Bucket.Put(context.Background()) // if err != nil { // fmt.Printf("Error creating bucket: %v\n", err) // } // Get bucket information // bucketInfo, _, err := cosClient.Bucket.Get(context.Background()) // if err != nil { // fmt.Printf("Error getting bucket info: %v\n", err) // } // fmt.Printf("Bucket Location: %s\n", bucketInfo.Location) // List buckets // buckets, _, err := cosClient.Service.Get(context.Background()) // if err != nil { // fmt.Printf("Error listing buckets: %v\n", err) // } // for _, b := range buckets.Buckets { // fmt.Printf("Bucket Name: %s\n", b.Name) // } // Delete a bucket (use with caution) // err = cosClient.Bucket.Delete(context.Background()) // if err != nil { // fmt.Printf("Error deleting bucket: %v\n", err) // } fmt.Println("Go SDK example setup complete. Uncomment operations to execute.") } ```