Initialization
Determine Endpoint
Before configuring the Endpoint for SDK usage, please refer to the developer guide section on [BOS Access Domain Name](BOS/Developer Guide/Basic concepts.md#Endpoint) to understand Endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer to[Region Selection Guide](Reference/Region Selection Instructions/Region.md).
Refer to the following link for region and endpoint
https://cloud.baidu.com/doc/BOS/s/akrqd2wcx
Common examples are as follows:
| Access region | Endpoint |
|---|---|
| BJ | bj.bcebos.com |
| BD | bd.bcebos.com |
| SU | su.bcebos.com |
| GZ | gz.bcebos.com |
| CD | cd.bcebos.com |
| HKG | hkg.bcebos.com |
| FWH | fwh.bcebos.com |
| FSH | fsh.bcebos.com |
Retrieve access key
To use Baidu AI Cloud BOS, you need a valid AK (Access Key ID) and SK (Secret Access Key) for signature certification. AK/SK are system-assigned strings used to identify users and perform signature certification for BOS. Your AK/SK information can be obtained and understood through the following steps:
Register a Baidu AI Cloud account
General process for using BOS C SDK
The following outlines the general steps for using the C SDK.
- Initialize the SDK.
- Configure the request option parameters.
- Set the necessary API parameters.
- Invoke the SDK API to send a request and receive the response.
Initialization
1int main(int argc, char *argv[])
2{
3 /* Call the bos_http_io_initialize method at the entrance of the program. This method will initialize some global resources internally, involving network, memory and other parts */
4 if (bos_http_io_initialize(NULL, 0) != BOSE_OK) {
5 exit(1);
6 }
7 /* Call the API of BOS SDK to upload or download files */
8 /* ... User logic code, omitted here */
9 /* Before the program ends, call the bos_http_io_deinitialize method to release the global resources allocated before */
10 bos_http_io_deinitialize();
11 return 0;
12}
Initialize request options
Users can refer to the following code to initialize request options:
1 bos_pool_t *pool;
2 bos_request_options_t *options;
3 bos_pool_create(&pool, NULL);
4 bos_string_t bucket;
5 bos_string_t object;
6 bos_string_t file;
7 bos_acl_e bos_acl = 3;
8 bos_table_t *resp_headers = NULL;
9 bos_table_t *headers = NULL;
10 options = bos_request_options_create(pool);
11 options->config = bos_config_create(options->pool);
12 bos_str_set(&options->config->endpoint, "bj.bcebos.com");
13 bos_str_set(&options->config->access_key_id, "xxxxxxxxxxx");
14 bos_str_set(&options->config->access_key_secret, "xxxxxxxxxxxxx");
15 bos_str_set(&options->config->sts_token, "<User’s StsToken>"); //Token for temporary key
16 bos_str_set(&bucket, TEST_BUCKET_NAME);
17 options->config->is_cname = 0;
In the code above, access_key_id corresponds to “Access Key ID” in the console. access_key_secret corresponds to “Access Key Secret” in the console. For the method to retrieve them, refer to the Guide - [Manage ACCESSKEY](Reference/Retrieve AK and SK/How to Obtain AKSK.md).
The method above uses the default domain name as BOS's service address. If you want to set a custom domain name, specify it using the ENDPOINT parameter.
Note:
The ENDPOINTparameter must use region-specific domain names (e.g., http://aihc.bj.baidubce.com for Beijing). If unspecified, it defaults to the Beijing regionhttp://bj.bcebos.com.
