General Examples 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
When you call an API in an instance of ObsClient, if no exception is thrown, the return value is valid and an instance or a sub-class instance of the ObsWebServiceResponse (SDK common response header) is returned. If any exception is thrown, obtain the error information from the instance of ObsException (SDK custom exception). ObsClient supports synchronous and asynchronous API callings. Examples are as follows:
Synchronous Call
Sample code:
ObsClient client;
ObsConfig config = new ObsConfig();
config.Endpoint = "https://your-endpoint";
// Create an instance of ObsClient.
client = new ObsClient("*** Provide your Access Key ***", "*** Provide your Secret Key ***", config);
// Call the API for creating a bucket in synchronous mode.
try
{
CreateBucketRequest request = new CreateBucketRequest
{
BucketName = "bucketname",
};
CreateBucketResponse response = client.CreateBucket(request);
Console.WriteLine("Create bucket response: {0}", response.StatusCode);
}
catch (ObsException ex)
{
Console.WriteLine("ErrorCode: {0}", ex.ErrorCode);
Console.WriteLine("ErrorMessage: {0}", ex.ErrorMessage);
}
Asynchronous Call
ObsClient client;
ObsConfig config = new ObsConfig();
config.Endpoint = "https://your-endpoint";
// Create an instance of ObsClient.
client = new ObsClient("*** Provide your Access Key ***", "*** Provide your Secret Key ***", config);
// Call the API for creating a bucket in asynchronous mode.
CreateBucketRequest request = new CreateBucketRequest
{
BucketName = "bucketname",
};
client.BeginCreateBucket(request, delegate(IAsyncResult ar){
try
{
CreateBucketResponse response = client.EndCreateBucket(ar);
Console.WriteLine("Create bucket response: {0}", response.StatusCode);
}
catch (ObsException ex)
{
Console.WriteLine("ErrorCode: {0}", ex.ErrorCode);
Console.WriteLine("ErrorMessage: {0}", ex.ErrorMessage);
}
}, null);
Last Article: Deleting an Object
Next Article: Initialization
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.