Help Center/ Object Storage Service/ C SDK Developer Guide (Ally Region)/ Getting Started (SDK for C)/ Initializing option (SDK for C)
Updated on 2026-01-16 GMT+08:00
Initializing option (SDK for C)
When the function of SDK for C is called, the option parameter must be passed. You can use function init_obs_options to initialize the option configuration, including the AK, SK, endpoint, bucket, timeout, and temporary authentication.
- Sample code for creating and initializing option using permanent access keys (AK/SK):
// Create and initialize option. obs_options option; init_obs_options(&option); option.bucket_options.host_name = "<your-endpoint>"; option.bucket_options.bucket_name = "<Your bucketname>"; // Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY. // Obtain an AK/SK pair on the management console. option.bucket_options.access_key = getenv("ACCESS_KEY_ID"); option.bucket_options.secret_access_key = getenv("SECRET_ACCESS_KEY");
- Sample code for creating and initializing option using temporary access keys (AK/SK and SecurityToken):
// Create and initialize option. obs_options option; init_obs_options(&option); option.bucket_options.host_name = "<your-endpoint>"; option.bucket_options.bucket_name = "<Your bucketname>"; // Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY. // Obtain an AK/SK pair on the management console. option.bucket_options.access_key = getenv("ACCESS_KEY_ID"); option.bucket_options.secret_access_key = getenv("SECRET_ACCESS_KEY"); option.bucket_options.token = getenv("SecurityToken");
- OBS is a global service. When obtaining temporary credentials, set the token scope to domain to make the token applicable to all projects and regions within an account.
Parent topic: Getting Started (SDK for C)
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot