./configuremakemake install
./configuremakemake install
./configuremakemake install
--with-apr option. The installation procedure is as follows:./configure --with-apr=/your/apr/install/pathmakemake install
./configuremakemake install
cmake .makemake install
/usr/local/apr/lib, and their pkgconfig directory is at /usr/local/apr/lib/pkgconfig. The cos_c_sdk, curl, and mxml are installed by default at /usr/local/lib, and their pkgconfig directory is at /usr/local/lib/pkgconfig.~/.bashrc file and add the following environment variables:export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/local/apr/lib/pkgconfigexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/apr/lib
. ~/.bashrc
cos.ap-guangzhou.myqcloud.com, and the endpoint for the global acceleration domain is cos.accelerate.myqcloud.com. You can prefix the endpoint with http or https. The SDK accesses COS via http by default. To access the Guangzhou region endpoint via https, use https://cos.ap-guangzhou.myqcloud.com.int main(int argc, char *argv[]){/* Call the cos_http_io_initialize method at the program entry. This method will initialize some global resources involving network, memory, and so on.*/if (cos_http_io_initialize(NULL, 0) != COSE_OK) {exit(1);}/* Call the APIs of the COS SDK to upload or download files. *//* ... Code for user logic is omitted here.*//* Before the program ends, call the cos_http_io_deinitialize method to release the previously allocated global resources.*/cos_http_io_deinitialize();return 0;}
/* Equivalent to apr_pool_t, used for memory pool for memory management, achieving code in apr library.*/cos_pool_t *pool;cos_request_options_t *options;/* Recreate a new memory pool, and the second parameter is NULL, indicating that it does not inherit from other memory pools.*/cos_pool_create(&pool, NULL);/* Create and initialize options, and this parameter mainly includes global configuration information such as endpoint, access_key_id, access_key_secret, is_cname, and curl parameters.* The memory for options is allocated by the pool. After the pool is released later, the memory for options is effectively released as well, eliminating the need for separate memory deallocation.*/options = cos_request_options_create(pool);options->config = cos_config_create(options->pool);/* cos_str_set uses a char* string to initialize the cos_string_t type.*/cos_str_set(&options->config->endpoint, "<YourEndpoint>"); //Fill in the Endpoint based on the COS service domain name corresponding to your region.cos_str_set(&options->config->access_key_id, "<YourSecretId>"); //SecretId for temporary secret key, see Temporary Secret Key Generation and Usage Guidelines at https://www.tencentcloud.com/document/product/436/14048cos_str_set(&options->config->access_key_secret, "<YourSecretKey>"); //SecretKey for temporary secret key, see Temporary Secret Key Generation and Usage Guidelines at https://www.tencentcloud.com/document/product/436/14048cos_str_set(&options->config->sts_token, "<YourStsToken>"); //Token for temporary secret key, see Temporary Secret Key Generation and Usage Guidelines at https://www.tencentcloud.com/document/product/436/14048cos_str_set(&options->config->appid, "<YourAppId>"); //Your AppId obtained after you register for the COS service./* Is CNAME used or not? */options->config->is_cname = 0;/* Use a custom domain name to access COS. *//*options->config->is_cname = 1;cos_str_set(&options->config->endpoint, "<CustomDomain>");*//* Used to set network-related parameters, such as timeout duration.*/options->ctl = cos_http_controller_create(options->pool, 0);/* Used to set whether to automatically add the Content-MD5 header to upload requests. When enable is COS_FALSE, the upload request will not automatically add the Content-MD5 header. When enable is COS_TRUE, the upload request will automatically add the Content-MD5 header. If this option is not set, the Content-MD5 header will be added by default. */cos_set_content_md5_enable(options->ctl, COS_FALSE);/* Used to set the address for request routing and port. Generally, you do not need to set this parameter. The request will be routed according to the result of domain resolution.*///cos_set_request_route(options->ctl, "192.168.12.34", 80);
/* Equivalent to apr_pool_t, used for memory pool for memory management, achieving code in apr library.*/cos_pool_t *pool;cos_request_options_t *options;/* Recreate a new memory pool, and the second parameter is NULL, indicating that it does not inherit from other memory pools.*/cos_pool_create(&pool, NULL);/* Create and initialize options, and this parameter mainly includes global configuration information such as endpoint, access_key_id, access_key_secret, is_cname, and curl parameters./* The memory of options is allocated by the pool. After the pool is released, the memory of options is also released, so there is no need to release the memory separately. */*/options = cos_request_options_create(pool);options->config = cos_config_create(options->pool);/* cos_str_set uses a char* string to initialize the cos_string_t type.*/cos_str_set(&options->config->endpoint, "<YourEndpoint>"); //Fill in the Endpoint based on the COS service domain name corresponding to your region.cos_str_set(&options->config->access_key_id, "<YourSecretId>"); //Your SecretId. It is recommended to use a sub-account key and follow the principle of least privilege to minimize usage risks. For information on obtaining sub-account keys, see https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1cos_str_set(&options->config->access_key_secret, "<YourSecretKey>"); //Your SecretKey. It is recommended to use a sub-account key and follow the principle of least privilege to minimize usage risks. For information on obtaining sub-account keys, see https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1cos_str_set(&options->config->appid, "<YourAppId>"); //Your AppId obtained after registration for the COS service is performed./* Is CNAME used or not? */options->config->is_cname = 0;/* Use a custom domain name to access COS. *//*options->config->is_cname = 1;cos_str_set(&options->config->endpoint, "<CustomDomain>");*//* Used to set network-related parameters, such as timeout duration.*/options->ctl = cos_http_controller_create(options->pool, 0);/* Used to set whether to automatically add the Content-MD5 header to upload requests. When enable is COS_FALSE, the upload request will not automatically add the Content-MD5 header. When enable is COS_TRUE, the upload request will automatically add the Content-MD5 header. If this option is not set, the Content-MD5 header will be added by default. */cos_set_content_md5_enable(options->ctl, COS_FALSE);/* Used to set the address for request routing and port. Generally, you do not need to set this parameter. The request will be routed according to the result of domain resolution.*///cos_set_request_route(options->ctl, "192.168.12.34", 80);
// put_bucket_demo.c#include <stdint.h>#include <stdlib.h>#include <sys/stat.h>#include <unistd.h>#include "cos_api.h"#include "cos_http_io.h"#include "cos_log.h"/*** This example demonstrates how to use the COS SDK for C to create a bucket.*/// Name of the COS bucket, in the format of [bucket]-[appid], such as examplebucket-1250000000. You can view it at https://console.tencentcloud.com/cos5/bucketchar bucket_name[] = "examplebucket-1250000000";// A unique user-level resource identifier for developers accessing COS services, used to identify resources. It can be obtained on the https://console.tencentcloud.com/cam/capi page.char appid[] = "1250000000";// Project Identity ID/Key credentials for developers, which can be obtained on the https://console.tencentcloud.com/cam/capi page.char secret_id[] = "xxxxxxxx";char secret_key[] = "xxxxxxxxxxxx";//endpoint is the domain information for accessing COS (without the bucket prefix, [bucket]-[appid] will be automatically prefixed when COS is accessed). For details, see the documentation at https://www.tencentcloud.com/document/product/436/6224.char endpoint[] = "cos.ap-xxx.myqcloud.com";// Whether to use a custom domain. If it is set to COS_TRUE, you need to modify the endpoint value to the custom domain when accessing COS.int is_cname = COS_FALSE;void init_test_config(cos_config_t* config, int is_cname) {cos_str_set(&config->endpoint, endpoint);cos_str_set(&config->access_key_id, secret_id);cos_str_set(&config->access_key_secret, secret_key);cos_str_set(&config->appid, appid);// cos_str_set(&config->sts_token, token); // token used when a temporary key is usedconfig->is_cname = is_cname; // whether to use a custom domain}void init_test_request_options(cos_request_options_t* options, int is_cname) {options->config = cos_config_create(options->pool);init_test_config(options->config, is_cname);options->ctl = cos_http_controller_create(options->pool, 0);}void log_status(cos_status_t* s) {cos_warn_log("status->code: %d", s->code);if (s->error_code)cos_warn_log("status->error_code: %s", s->error_code);if (s->error_msg)cos_warn_log("status->error_msg: %s", s->error_msg);if (s->req_id)cos_warn_log("status->req_id: %s", s->req_id);}void put_bucket_demo() {cos_pool_t *p = NULL;cos_status_t *s = NULL;cos_request_options_t *options = NULL;cos_acl_e cos_acl = COS_ACL_PRIVATE;cos_string_t bucket;cos_table_t *resp_headers = NULL;cos_pool_create(&p, NULL);options = cos_request_options_create(p);init_test_request_options(options, is_cname);cos_str_set(&bucket, bucket_name);//create test buckets = cos_create_bucket(options, &bucket, cos_acl, &resp_headers);log_status(s);cos_pool_destroy(p);}int main() {if (cos_http_io_initialize(NULL, 0) != COSE_OK) {exit(1);}// set log level, default COS_LOG_WARNcos_log_set_level(COS_LOG_ERROR);put_bucket_demo();// cos_http_io_deinitialize lastcos_http_io_deinitialize();return 0;}
// get_bucket_list_demo.c#include <stdint.h>#include <stdlib.h>#include <sys/stat.h>#include <unistd.h>#include "cos_api.h"#include "cos_http_io.h"#include "cos_log.h"/*** This example demonstrates how to use the COS SDK for C to obtain the bucket list.*/// A unique user-level resource identifier for developers accessing COS services, used to identify resources. It can be obtained on the https://console.tencentcloud.com/cam/capi page.char appid[] = "1250000000";// Project Identity ID/Key credentials for developers, which can be obtained on the https://console.tencentcloud.com/cam/capi page.char secret_id[] = "xxxxxxxx";char secret_key[] = "xxxxxxxxxxxx";//endpoint is the domain information for accessing COS (without the bucket prefix, [bucket]-[appid] will be automatically prefixed when COS is accessed). For details, see the documentation at https://www.tencentcloud.com/document/product/436/6224.char endpoint[] = "cos.ap-xxx.myqcloud.com";// Whether to use a custom domain. If it is set to COS_TRUE, you need to modify the endpoint value to the custom domain when accessing COS.int is_cname = COS_FALSE;void init_test_config(cos_config_t* config, int is_cname) {cos_str_set(&config->endpoint, endpoint);cos_str_set(&config->access_key_id, secret_id);cos_str_set(&config->access_key_secret, secret_key);cos_str_set(&config->appid, appid);// cos_str_set(&config->sts_token, token); // token used when a temporary key is usedconfig->is_cname = is_cname; // whether to use a custom domain}void init_test_request_options(cos_request_options_t* options, int is_cname) {options->config = cos_config_create(options->pool);init_test_config(options->config, is_cname);options->ctl = cos_http_controller_create(options->pool, 0);}void log_status(cos_status_t* s) {cos_warn_log("status->code: %d", s->code);if (s->error_code)cos_warn_log("status->error_code: %s", s->error_code);if (s->error_msg)cos_warn_log("status->error_msg: %s", s->error_msg);if (s->req_id)cos_warn_log("status->req_id: %s", s->req_id);}void get_bucket_list_demo() {cos_pool_t *pool = NULL;cos_status_t *status = NULL;cos_request_options_t *options = NULL;cos_get_service_params_t *list_params = NULL;cos_table_t *resp_headers = NULL;//Creating a memory poolcos_pool_create(&pool, NULL);//Initializing the request optionsoptions = cos_request_options_create(pool);options->config = cos_config_create(options->pool);init_test_request_options(options, is_cname);options->ctl = cos_http_controller_create(options->pool, 0);//Creating parameters for get service, which retrieves all buckets by defaultlist_params = cos_create_get_service_params(options->pool);//If all_region is set to 0, the query will only be performed based on the region of options->config->endpoint//list_params->all_region = 0;status = cos_get_service(options, list_params, &resp_headers);log_status(status);if (!cos_status_is_ok(status)) {cos_pool_destroy(pool);return;}// View the resultcos_get_service_content_t *content = NULL;char *line = NULL;cos_list_for_each_entry(cos_get_service_content_t, content, &list_params->bucket_list, node) {line = apr_psprintf(options->pool, "%.*s\\t%.*s\\t%.*s\\n", content->bucket_name.len, content->bucket_name.data, content->location.len, content->location.data, content->creation_date.len, content->creation_date.data);printf("%s", line);}cos_pool_destroy(pool);}int main() {if (cos_http_io_initialize(NULL, 0) != COSE_OK) {exit(1);}// set log level, default COS_LOG_WARNcos_log_set_level(COS_LOG_ERROR);get_bucket_list_demo();// cos_http_io_deinitialize lastcos_http_io_deinitialize();return 0;}
// list_object_demo.c#include <stdint.h>#include <stdlib.h>#include <sys/stat.h>#include <unistd.h>#include "cos_api.h"#include "cos_http_io.h"#include "cos_log.h"/*** This example demonstrates how to use the COS C SDK to list objects (list all objects in a bucket).*/// Name of the COS bucket, in the format of [bucket]-[appid], such as examplebucket-1250000000. You can view it at https://console.tencentcloud.com/cos5/bucketchar bucket_name[] = "examplebucket-1250000000";// A unique user-level resource identifier for developers accessing COS services, used to identify resources. It can be obtained on the https://console.tencentcloud.com/cam/capi page.char appid[] = "1250000000";// Project Identity ID/Key credentials for developers, which can be obtained on the https://console.tencentcloud.com/cam/capi page.char secret_id[] = "xxxxxxxx";char secret_key[] = "xxxxxxxxxxxx";//endpoint is the domain information for accessing COS (without the bucket prefix, [bucket]-[appid] will be automatically prefixed when COS is accessed). For details, see the documentation at https://www.tencentcloud.com/document/product/436/6224.char endpoint[] = "cos.ap-xxx.myqcloud.com";// Whether to use a custom domain. If it is set to COS_TRUE, you need to modify the endpoint value to the custom domain when accessing COS.int is_cname = COS_FALSE;void init_test_config(cos_config_t* config, int is_cname) {cos_str_set(&config->endpoint, endpoint);cos_str_set(&config->access_key_id, secret_id);cos_str_set(&config->access_key_secret, secret_key);cos_str_set(&config->appid, appid);// cos_str_set(&config->sts_token, token); // token used when a temporary key is usedconfig->is_cname = is_cname; // whether to use a custom domain}void init_test_request_options(cos_request_options_t* options, int is_cname) {options->config = cos_config_create(options->pool);init_test_config(options->config, is_cname);options->ctl = cos_http_controller_create(options->pool, 0);}void log_status(cos_status_t* s) {cos_warn_log("status->code: %d", s->code);if (s->error_code)cos_warn_log("status->error_code: %s", s->error_code);if (s->error_msg)cos_warn_log("status->error_msg: %s", s->error_msg);if (s->req_id)cos_warn_log("status->req_id: %s", s->req_id);}void list_all_objects_demo() {cos_pool_t* p = NULL;cos_status_t* s = NULL;cos_request_options_t* options = NULL;cos_string_t bucket;cos_table_t* resp_headers;int is_truncated = 1;cos_string_t marker;cos_pool_create(&p, NULL);options = cos_request_options_create(p);init_test_request_options(options, is_cname);cos_str_set(&bucket, bucket_name);// list object (get bucket)cos_list_object_params_t* list_params = NULL;list_params = cos_create_list_object_params(p);// Setting the maximum number of objects to be traversed, with a maximum number of 1000 objects supported by a listobject.list_params->max_ret = 1000;cos_str_set(&marker, "");while (is_truncated) {list_params->marker = marker;cos_list_init(&list_params->object_list);s = cos_list_object(options, &bucket, list_params, &resp_headers);if (!cos_status_is_ok(s)) {printf("list object failed, req_id:%s\\n", s->req_id);break;}// list_params->object_list returns the listed object(s).cos_list_object_content_t* content = NULL;cos_list_for_each_entry(cos_list_object_content_t, content, &list_params->object_list, node) {printf("object: %s\\n", content->key.data);}is_truncated = list_params->truncated;marker = list_params->next_marker;}cos_pool_destroy(p);}int main() {if (cos_http_io_initialize(NULL, 0) != COSE_OK) {exit(1);}// set log level, default COS_LOG_WARNcos_log_set_level(COS_LOG_WARN);list_all_objects_demo();// cos_http_io_deinitialize lastcos_http_io_deinitialize();return 0;}
// put_object_demo.c#include <stdint.h>#include <stdlib.h>#include <sys/stat.h>#include <unistd.h>#include "cos_api.h"#include "cos_http_io.h"#include "cos_log.h"/*** This sample demonstrates how to use the COS SDK for C to perform object uploads (uploading local files).*/// Name of the COS bucket, in the format of [bucket]-[appid], such as examplebucket-1250000000. You can view it at https://console.tencentcloud.com/cos5/bucketchar bucket_name[] = "examplebucket-1250000000";// A unique user-level resource identifier for developers accessing COS services, used to identify resources. It can be obtained on the https://console.tencentcloud.com/cam/capi page.char appid[] = "1250000000";// Project Identity ID/Key credentials for developers, which can be obtained on the https://console.tencentcloud.com/cam/capi page.char secret_id[] = "xxxxxxxx";char secret_key[] = "xxxxxxxxxxxx";//endpoint is the domain information for accessing COS (without the bucket prefix, [bucket]-[appid] will be automatically prefixed when COS is accessed). For details, see the documentation at https://www.tencentcloud.com/document/product/436/6224.char endpoint[] = "cos.ap-xxx.myqcloud.com";// Whether to use a custom domain. If it is set to COS_TRUE, you need to modify the endpoint value to the custom domain when accessing COS.int is_cname = COS_FALSE;// Object namechar object_name[] = "test.txt";// Local file pathchar file_path[] = "test.txt";void init_test_config(cos_config_t* config, int is_cname) {cos_str_set(&config->endpoint, endpoint);cos_str_set(&config->access_key_id, secret_id);cos_str_set(&config->access_key_secret, secret_key);cos_str_set(&config->appid, appid);// cos_str_set(&config->sts_token, token); // token used when the temporary key is usedconfig->is_cname = is_cname; // whether to use a custom domain}void init_test_request_options(cos_request_options_t* options, int is_cname) {options->config = cos_config_create(options->pool);init_test_config(options->config, is_cname);options->ctl = cos_http_controller_create(options->pool, 0);}void log_status(cos_status_t* s) {cos_warn_log("status->code: %d", s->code);if (s->error_code)cos_warn_log("status->error_code: %s", s->error_code);if (s->error_msg)cos_warn_log("status->error_msg: %s", s->error_msg);if (s->req_id)cos_warn_log("status->req_id: %s", s->req_id);}void put_object_from_file_demo() {cos_pool_t* p = NULL;cos_status_t* s = NULL;cos_request_options_t* options = NULL;cos_string_t bucket;cos_string_t object;cos_string_t file;cos_table_t* resp_headers = NULL;cos_table_t* headers = NULL;// Create a memory poolcos_pool_create(&p, NULL);// Initialize request options.options = cos_request_options_create(p);init_test_request_options(options, is_cname);cos_str_set(&bucket, bucket_name);// The speed limit value ranges from 819200 - 838860800 (100KB/s - 100MB/s). Values outside this range will return a 400 error.// headers = cos_table_make(p, 1);// cos_table_add_int(headers, "x-cos-traffic-limit", 819200);// Upload object.cos_str_set(&file, file_path);cos_str_set(&object, object_name);s = cos_put_object_from_file(options, &bucket, &object, &file, headers, &resp_headers);if (cos_status_is_ok(s)) {printf("put object succeeded\\n");} else {printf("put object failed\\n");}log_status(s);// Destroy the memory pool.cos_pool_destroy(p);}int main() {if (cos_http_io_initialize(NULL, 0) != COSE_OK) {exit(1);}// set log level, default COS_LOG_WARN// cos_log_set_level(COS_LOG_WARN);put_object_from_file_demo();// cos_http_io_deinitialize lastcos_http_io_deinitialize();return 0;}
// get_object_demo.c#include <stdint.h>#include <stdlib.h>#include <sys/stat.h>#include <unistd.h>#include "cos_api.h"#include "cos_http_io.h"#include "cos_log.h"/*** This sample demonstrates how to use the COS SDK for C to perform object downloads (simple downloading).*/// Name of the COS bucket, in the format of [bucket]-[appid], such as examplebucket-1250000000. You can view it at https://console.tencentcloud.com/cos5/bucketchar bucket_name[] = "examplebucket-1250000000";// A unique user-level resource identifier for developers accessing COS services, used to identify resources. It can be obtained on the https://console.tencentcloud.com/cam/capi page.char appid[] = "1250000000";// Project Identity ID/Key credentials for developers, which can be obtained on the https://console.tencentcloud.com/cam/capi page.char secret_id[] = "xxxxxxxx";char secret_key[] = "xxxxxxxxxxxx";//endpoint is the domain information for accessing COS (without the bucket prefix, [bucket]-[appid] will be automatically prefixed when COS is accessed). For details, see the documentation at https://www.tencentcloud.com/document/product/436/6224.char endpoint[] = "cos.ap-xxx.myqcloud.com";// Whether to use a custom domain. If it is set to COS_TRUE, you need to modify the endpoint value to the custom domain when accessing COS.int is_cname = COS_FALSE;// Object namechar object_name[] = "test.txt";// Local file pathchar file_path[] = "test.txt";void init_test_config(cos_config_t* config, int is_cname) {cos_str_set(&config->endpoint, endpoint);cos_str_set(&config->access_key_id, secret_id);cos_str_set(&config->access_key_secret, secret_key);cos_str_set(&config->appid, appid);// cos_str_set(&config->sts_token, token); // token used when a temporary key is usedconfig->is_cname = is_cname; // whether to use a custom domain}void init_test_request_options(cos_request_options_t* options, int is_cname) {options->config = cos_config_create(options->pool);init_test_config(options->config, is_cname);options->ctl = cos_http_controller_create(options->pool, 0);}void log_status(cos_status_t* s) {cos_warn_log("status->code: %d", s->code);if (s->error_code)cos_warn_log("status->error_code: %s", s->error_code);if (s->error_msg)cos_warn_log("status->error_msg: %s", s->error_msg);if (s->req_id)cos_warn_log("status->req_id: %s", s->req_id);}void get_object_to_file_demo() {cos_pool_t *p = NULL;cos_status_t *s = NULL;cos_request_options_t *options = NULL;cos_string_t bucket;cos_string_t object;cos_table_t *resp_headers;cos_string_t file;cos_table_t *headers = NULL;cos_table_t *params = NULL;cos_pool_create(&p, NULL);options = cos_request_options_create(p);init_test_request_options(options, is_cname);cos_str_set(&bucket, bucket_name);cos_str_set(&file, file_path);cos_str_set(&object, object_name);// The speed limit value ranges from 819200 - 838860800 (100KB/s - 100MB/s). Values outside this range will return a 400 error.// headers = cos_table_make(p, 1);// cos_table_add_int(headers, "x-cos-traffic-limit", 819200);s = cos_get_object_to_file(options, &bucket, &object, headers, params, &file, &resp_headers);log_status(s);{int i = 0;apr_array_header_t * pp = (apr_array_header_t *) apr_table_elts(resp_headers);for ( ; i < pp->nelts; i++) {apr_table_entry_t *ele = (apr_table_entry_t *)pp->elts+i;printf("%s: %s\\n", ele->key, ele->val);}}cos_pool_destroy(p);}int main() {if (cos_http_io_initialize(NULL, 0) != COSE_OK) {exit(1);}// set log level, default COS_LOG_WARNcos_log_set_level(COS_LOG_WARN);get_object_to_file_demo();// cos_http_io_deinitialize lastcos_http_io_deinitialize();return 0;}
// delete_object_demo.c#include <stdint.h>#include <stdlib.h>#include <sys/stat.h>#include <unistd.h>#include "cos_api.h"#include "cos_http_io.h"#include "cos_log.h"/*** This sample demonstrates how to use the COS SDK for C to perform object deletion (single object deletion).*/// Name of the COS bucket, in the format of [bucket]-[appid], such as examplebucket-1250000000. You can view it at https://console.tencentcloud.com/cos5/bucketchar bucket_name[] = "examplebucket-1250000000";// A unique user-level resource identifier for developers accessing COS services, used to identify resources. It can be obtained on the https://console.tencentcloud.com/cam/capi page.char appid[] = "1250000000";// Project Identity ID/Key credentials for developers, which can be obtained on the https://console.tencentcloud.com/cam/capi page.char secret_id[] = "xxxxxxxx";char secret_key[] = "xxxxxxxxxxxx";//endpoint is the domain information for accessing COS (without the bucket prefix, [bucket]-[appid] will be automatically prefixed when COS is accessed). For details, see the documentation at https://www.tencentcloud.com/document/product/436/6224.char endpoint[] = "cos.ap-xxx.myqcloud.com";// Whether to use a custom domain. If set to COS_TRUE, you need to modify the endpoint value to the custom domain when accessing COS.int is_cname = COS_FALSE;// Object namechar object_name[] = "test.txt";void init_test_config(cos_config_t* config, int is_cname) {cos_str_set(&config->endpoint, endpoint);cos_str_set(&config->access_key_id, secret_id);cos_str_set(&config->access_key_secret, secret_key);cos_str_set(&config->appid, appid);// cos_str_set(&config->sts_token, token); // token used when a temporary key is usedconfig->is_cname = is_cname; // whether to use a custom domain}void init_test_request_options(cos_request_options_t* options, int is_cname) {options->config = cos_config_create(options->pool);init_test_config(options->config, is_cname);options->ctl = cos_http_controller_create(options->pool, 0);}void log_status(cos_status_t* s) {cos_warn_log("status->code: %d", s->code);if (s->error_code)cos_warn_log("status->error_code: %s", s->error_code);if (s->error_msg)cos_warn_log("status->error_msg: %s", s->error_msg);if (s->req_id)cos_warn_log("status->req_id: %s", s->req_id);}void delete_object_demo() {cos_pool_t *p = NULL;cos_status_t *s = NULL;cos_request_options_t *options = NULL;cos_string_t bucket;cos_string_t object;cos_string_t src_object;cos_string_t src_endpoint;cos_table_t *resp_headers = NULL;//Creating a memory pool.cos_pool_create(&p, NULL);//Initializing the request options.options = cos_request_options_create(p);init_test_request_options(options, is_cname);cos_str_set(&bucket, bucket_name);//Setting the object.cos_str_set(&object, object_name);s = cos_delete_object(options, &bucket, &object, &resp_headers);log_status(s);if (cos_status_is_ok(s)) {printf("delete object succeeded\\n");} else {printf("delete object failed\\n");}//Destroying the memory pool.cos_pool_destroy(p);}int main() {if (cos_http_io_initialize(NULL, 0) != COSE_OK) {exit(1);}// set log level, default COS_LOG_WARNcos_log_set_level(COS_LOG_WARN);delete_object_demo();// cos_http_io_deinitialize lastcos_http_io_deinitialize();return 0;}
pkg-config --cflags --libs apr-1 apr-util-1 mxml libcurl
-I/usr/local/apr/include/apr-1 -DLINUX -D_GNU_SOURCE -g -O2 -pthread -I/usr/local/include -D_THREAD_SAFE -D_REENTRANT -L/usr/local/apr/lib -laprutil-1 -lexpat -lapr-1 -lrt -lcrypt -ldl -L/usr/local/lib -lmxml -lpthread -lcurl
-I/usr/local/include/cos_c_sdk -lcos_c_sdk, and the final compilation options are as follows:-I/usr/local/include/cos_c_sdk -I/usr/local/apr/include/apr-1 -I/usr/local/include -DLINUX -D_GNU_SOURCE -g -O2 -pthread -D_THREAD_SAFE -D_REENTRANT -L/usr/local/lib -lcos_c_sdk -L/usr/local/apr/lib -laprutil-1 -lexpat -lapr-1 -lrt -lcrypt -ldl -lmxml -lpthread -lcurl
pkg-config --cflags --libs cos_c_sdk apr-1 apr-util-1 mxml libcurl to generate compilation options with cos-c-sdk information.gcc get_bucket_list_demo.c -o get_bucket_list_demo -I/usr/local/include/cos_c_sdk -I/usr/local/apr/include/apr-1 -I/usr/local/include -DLINUX -D_GNU_SOURCE -g -O2 -pthread -D_THREAD_SAFE -D_REENTRANT -L/usr/local/lib -lcos_c_sdk -L/usr/local/apr/lib -laprutil-1 -lexpat -lapr-1 -lrt -lcrypt -ldl -lmxml -lpthread -lcurl
./get_bucket_list_demo
Feedback