Creating an Instance of ObsClient
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference
ObsClient functions as the Android client for accessing OBS. It offers users a series of APIs for interaction with OBS and is used for managing and performing operations on resources, such as buckets and objects, stored in OBS. To use OBS Android SDK to send a request to OBS, you need to initialize an instance of ObsClient and modify the default configurations in ObsConfiguration based on actual needs.
- If you use the endpoint to create an instance of ObsClient, all parameters are in their default values and cannot be modified. Sample code is as follows:
- Sample code for creating an instance of ObsClient using permanent access keys (AK/SK):
String endPoint = "https://your-endpoint"; String ak = "*** Provide your Access Key ***"; String sk = "*** Provide your Secret Key ***"; // Create an instance of ObsClient. ObsClient obsClient = new ObsClient(ak, sk, endPoint); // Use the instance to access OBS. // Close ObsClient. obsClient.close();
- Sample code for creating an instance of ObsClient using temporary access keys (AK/SK and security token):
String endPoint = "https://your-endpoint"; String ak = "*** Provide your Access Key ***"; String sk = "*** Provide your Secret Key ***"; String securityToken = "*** Provide your Security Token ***"; // Create an instance of ObsClient. ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); // Use the instance to access OBS. // Close ObsClient. obsClient.close();
- Sample code for creating an instance of ObsClient using permanent access keys (AK/SK):
- If you use ObsConfiguration to create an instance of ObsClient, you can set configuration parameters as needed during the creation. After the instance is created, the parameters cannot be modified. For parameter details, see Configuring an Instance of ObsClient. Sample code is as follows:
String endPoint = "https://your-endpoint"; String ak = "*** Provide your Access Key ***"; String sk = "*** Provide your Secret Key ***"; // Create an instance of ObsConfiguration. ObsConfiguration config = new ObsConfiguration(); config.setEndPoint(endPoint); config.setSocketTimeout(30000); config.setMaxErrorRetry(1); // Create an instance of ObsClient. ObsClient obsClient = new ObsClient(ak, sk, config); // Use the instance to access OBS. // Close ObsClient. obsClient.close();
- The project can contain one or more instances of ObsClient.
- ObsClient is thread-safe and can be simultaneously used by multiple threads.
After you call ObsClient.close to close an instance of ObsClient, the instance cannot be used any more.
Last Article: Configuring the AK/SK
Next Article: Configuring an Instance of ObsClient
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.